def setUp(self): temp_dir = DirectoryInfo(Environment.GetEnvironmentVariable("TEMP")) # myDocuments = DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) self.temp_dir = temp_dir.CreateSubdirectory('tempDir') self.temp_dir_path = self.temp_dir.ToString() self.file1 = FileInfo(self.temp_dir_path + '\\file1.txt') self.file2 = FileInfo(self.temp_dir_path + '\\file2.txt') self.file3 = FileInfo(self.temp_dir_path + '\\file3.txt') sw = self.file1.CreateText() sw.WriteLine("Hello1") sw.Close() sw = self.file2.CreateText() sw.WriteLine("Hello2") sw.Close() sw = self.file3.CreateText() sw.WriteLine("Hello3") sw.Close() today = DateTime.Now one_day_old = today.AddDays(-1).ToString("yyyy.MM.dd") two_days_old = today.AddDays(-2).ToString("yyyy.MM.dd") self.file1.CreationTime = DateTime.Parse(today.ToString("yyyy.MM.dd")) self.file2.CreationTime = DateTime.Parse(one_day_old) self.file3.CreationTime = DateTime.Parse(two_days_old) print "\r myDocuments temp path = [%s]" % self.temp_dir_path print "CreationTime file1 = [%s]" % self.file1.CreationTime print "CreationTime file2 = [%s]" % self.file2.CreationTime print "CreationTime file3 = [%s]" % self.file3.CreationTime
def recycleBin(): summary = printHeader("RECYCLE BIN") if WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator): for drive in DriveInfo.GetDrives(): try: recycleDir = DirectoryInfo(drive.Name + "$Recycle.Bin\\") for dir in DirectoryInfo.EnumerateDirectories(recycleDir): fileList = DirectoryInfo.GetFiles(dir) summary += printSubheader("Directory: {0}".format(dir.FullName)) for file in fileList: name = file.FullName.split("\\")[-1] if name.startswith("$I"): info = open(file.FullName, "r").read() summary += "{0}\t{1}\n".format(name.replace("$I", "$R"), info[26::2]) except IOError: pass else: for drive in DriveInfo.GetDrives(): try: recycleDir = drive.Name + "$Recycle.Bin\\" user = WindowsIdentity.GetCurrent() fileList = Directory.GetFiles(recycleDir + user.Owner.ToString()) summary += printSubheader("Directory: {0}".format(recycleDir + user.Owner.ToString())) for file in fileList: name = file.split("\\")[-1] if name.startswith("$I"): info = open(file, "r").read() summary += "{0}\t{1}\n".format(name.replace("$I", "$R"), info[26::2]) except IOError: pass return summary
def interestingFiles(): filetypes = [ "*.ps1", "*pass*", "*diagram*", "*.pdf", "*.vsd", "*.doc", "*.docx", "*.xls", "*.xlsx", "*.kdbx", "*.key", "KeePass.config"] dirs = [ Env.GetEnvironmentVariable("ProgramFiles"), Env.GetEnvironmentVariable("ProgramFiles(x86)"), Env.GetEnvironmentVariable("USERPROFILE") + "\Desktop", Env.GetEnvironmentVariable("USERPROFILE") + "\Documents", ] indexedFiles() filesSummary = printHeader("INTERESTING FILES") filesSummary += printSubheader ("Logical Drives") for drive in DriveInfo.GetDrives(): try: filesSummary += "Drive {0}\n".format(drive.Name) filesSummary += "\tDrive Type: {0}\n".format(drive.DriveType) filesSummary += "\tVolume label: {0}\n".format(drive.VolumeLabel) filesSummary += "\tFile System: {0}\n".format(drive.DriveFormat) filesSummary += "\tAvailable Space for user: \t{0}\n".format(drive.AvailableFreeSpace) filesSummary += "\tTotal Available Space: \t\t{0}\n".format(drive.TotalFreeSpace) filesSummary += "\tTotal Drive Space: \t\t{0}\n".format(drive.TotalSize) except IOError: continue filesSummary += printSubheader ("DIRECTORY LISTINGS") for dir in dirs: dirInfo = DirectoryInfo(dir) filesSummary += dir + "\n" for d in dirInfo.GetDirectories(): filesSummary += " " + d.Name + "\n" filesSummary += "\n" filesSummary += printSubheader ("FILES BY EXTENSION") profile = DirectoryInfo(Env.GetEnvironmentVariable("USERPROFILE")) for t in filetypes: filesSummary = recursiveFiles(profile, t, filesSummary) filesSummary += printSubheader ("POWERSHELL HISTORY") psHistFile = Env.GetEnvironmentVariable("APPDATA") + "\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt" try: history = open(psHistFile, "r").readlines()[-50:] filesSummary += "".join(history) except IndexError: history = open(psHistFile, "r").readlines() filesSummary += "".join(history) except IOError: filesSummary += "No history!\n" filesSummary += printSubheader ("HOSTS FILE") filesSummary += open(Env.GetEnvironmentVariable("WINDIR") + "\System32\drivers\etc\hosts", "r").read() return filesSummary
def convert_files(doc_path): directory = DirectoryInfo(doc_path) files = directory.GetFiles("*.doc") for file_info in files: text = doc_to_text(Path.Combine(doc_path, file_info.Name)) stream_writer = File.CreateText( Path.GetFileNameWithoutExtension(file_info.Name) + ".txt") stream_writer.Write(text) stream_writer.Close() return
def GetDirectoryParts(folderPath): parts = [] current = DirectoryInfo(folderPath) while current is not None: parts.insert(0, current.Name) current = current.Parent return parts
def browserEnum(): summary = printHeader("BROWSER ENUM") regex = Regex('(http|ftp|https|file)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?') #Active IE Urls summary += printSubheader("ACTIVE EXPLORER URLS") app = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application")) summary += "\n".join([w.LocationUrl() for w in app.Windows()]) #Chrome History summary += printSubheader("\n\nChrome History") try: cHistPath = "{0}\Users\{1}\AppData\Local\Google\Chrome\User Data\Default\History".format(Env.GetEnvironmentVariable("systemdrive"), Env.UserName) cHist = open(cHistPath, "r").read() summary += "\n".join(["[*] {0}\n".format(m.Value) for m in regex.Matches(cHist)][-10:]) except: pass summary += printSubheader("\nChrome Bookmarks") #Chrome Bookmarks try: cBMPath = "{0}\Users\{1}\AppData\Local\Google\Chrome\User Data\Default\Bookmarks".format(Env.GetEnvironmentVariable("systemdrive"), Env.UserName) js = JavaScriptSerializer() cBM = js.DeserializeObject(open(cBMPath, "r").read()) urls = cBM["roots"]["bookmark_bar"]["children"] for url in urls: u = url['url'] d = url['name'] summary += "[*] {0}\n{1}\n\n".format(d, u) except: pass summary += printSubheader("Firefox History") #Firefox History try: regex = Regex('(http|ftp|https|file)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?') fHistPath = "{0}\Users\{1}\AppData\Roaming\Mozilla\Firefox\Profiles".format(Env.GetEnvironmentVariable("systemdrive"), Env.UserName) for path in DirectoryInfo(fHistPath).EnumerateDirectories("*.default"): places = open(path.FullName + "\places.sqlite", "r").read() summary += "\n".join(["[*] {0}\n".format(m.Value) for m in regex.Matches(places)][:10]) except: pass summary += printSubheader("IE History") typedUrlPath = "\Software\Microsoft\Internet Explorer\TypedURLs" for sid in Registry.Users.GetSubKeyNames(): if sid != ".DEFAULT" and not sid.endswith("Classes"): try: typedUrlsKey = Registry.Users.OpenSubKey(sid + typedUrlPath) if typedUrlsKey != None: summary += "[{0}][{1}]\n".format(sid, SecurityIdentifier(sid.ToString()).Translate(NTAccount)) for value in typedUrlsKey.GetValueNames(): summary += "\t{0}\n".format(typedUrlsKey.GetValue(value)) summary += "\n" except SystemError: pass return summary
def testDirectorySize(self): self.assertEqual(30, DirectoryListing.getDirSize(DirectoryInfo(self.dir_to_check)))
def get_ik_list(): import UserData import os.path from System.IO import DirectoryInfo di = DirectoryInfo(os.path.abspath(os.path.join(UserData.Path, "IKPose"))) return [x.Name for x in di.GetFiles()]
import clr clr.AddReference( 'C:\\Program Files\\Siemens\\Automation\\Portal V15_1\PublicAPI\\V15.1\\Siemens.Engineering.dll' ) from System.IO import DirectoryInfo import Siemens.Engineering as tia project_path = DirectoryInfo('C:\\Jonas\\TIA') project_name = 'PythonTest' #Starting TIA print('Starting TIA with UI') mytia = tia.TiaPortal(tia.TiaPortalMode.WithUserInterface) #Creating new project print('Creating project') myproject = mytia.Projects.Create(project_path, project_name) #Addding Stations print('Creating station 1') station1_mlfb = 'OrderNumber:6ES7 515-2AM01-0AB0/V2.6' station1 = myproject.Devices.CreateWithItem(station1_mlfb, 'station1', 'station1') print('Creating station 2') station2_mlfb = 'OrderNumber:6ES7 518-4AP00-0AB0/V2.6' station2 = myproject.Devices.CreateWithItem(station2_mlfb, 'station2', 'station2') print("Press any key to quit") input()
# deal with the input # IN[0] - an array of modelpaths # IN[1] - a family mapping file path # IN[2] - a parameter mapping file path # IN[3] - an output directory # IN[4] - a viewname if isinstance(IN[0], list): paths = IN[0] else: paths = [IN[0]] famMapFile = IN[1] psetsFile = IN[2] di = DirectoryInfo(IN[3]) if di.Exists: outpath = IN[3] else: outpath = \ Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) viewName = IN[4] Debug.WriteLine(famMapFile) res = [] uiapp = DocMgr.Instance.CurrentUIApplication app = DocMgr.Instance.CurrentUIApplication.Application for p in paths: doc = OpenDocument(app, p)