Jump to content

Tsiyoshi

Active Members
  • Posts

    26
  • Joined

  • Last visited

Tsiyoshi's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. Thank you jguinch, mikell, orbs. Appreciate your input. Like mikell said - the arrays didn't have the same elements, It was easiest to make that change and now it works fine. Thank you again.
  2. Hello, I am trying to build a script that reads a text file with multiple lines (every line has a folder name that needs to be deleted). Then I want to look for the folder name in the folder list (using _FileListToArrayRec) and if the folder name is found - delete it. This is the code I have so far, but it fails on line 43 - "Array variable has incorrect number of subscripts or subscript dimension range exceeded" would appreciate some help. #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <file.au3> #Include <Date.au3> #include <Array.au3> ; ***** Create local logs DirCreate (@WindowsDir & "\Log\") $dir = (@WindowsDir & "\Log\") $log = FileOpen (@WindowsDir & "\Log\log.log",2+256) Eof() Func Eof() ; Create a constant variable in Local scope of the filepath that will be read/written to. Global Const $sFilePath = @scriptdir & "\folders.txt" ; Open the file for reading and store the handle to a variable. Global $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf ; Read the contents of the file using the handle returned by FileOpen. Global $aArray = FileReadToArray ($hFileOpen) For $i = 0 To UBound($aArray) - 1 ; Loop through the array. MsgBox($MB_SYSTEMMODAL, "", $aArray[$i]) Next $sRoot = (@ScriptDir) ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList _ArrayDisplay($aList) For $i = 1 To $aList[0] If FileExists($sRoot & "\" & $aList[$i] & "\" & $aArray[$i]) Then _filewritelog ($log, "Deleting, " & $aArray[$i]) Next FileClose($hFileOpen) EndFunc
  3. Thanks you. I can use FileExists() but to the best of my knowlege, I can run the search from the text file on a root folder directory, for example: If FileExists(@ScriptDir & "\" & $sFileRead) But I need the search to run on numerous subfolders (which is why I thought about using _FileListToArrayRec.
  4. Hi there! I'm trying to delete old folders that are not in use anymore - the names of those folders are in a text file. So what I want to do is have the script read the text file and compare the names in it to the actual folder names inside, and if the folder name from the list is found on the computer - delete it. I am using filereadline to read from the text file, and _FileListToArrayRec to compare with the actual folders on the computer, but I need some help with the basic code. would appreciate the help.. #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <file.au3> #Include <Date.au3> #include <Array.au3> ; ***** Create local logs DirCreate (@scriptdir & "test") $dir = (@scriptdir & "test"") $log = FileOpen (@scriptdir & "test"\test.log",2) ; Function for reading - text file Eof() Func Eof() ; Create a constant variable in Local scope of the filepath that will be read/written to. Global Const $sFilePath = @scriptdir & "\systems.txt" ; Open the file for reading and store the handle to a variable. Global $hFileOpen = FileOpen($sFilePath, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf ; Read the contents of the file using the handle returned by FileOpen. Global $sFileRead = FileReadLine($hFileOpen, 1) ; Close the handle returned by FileOpen. ;FileClose($hFileOpen) ; Display the contents of the file. MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & $sFileRead) EndFunc ; put the root in a variable $sRoot = (@ScriptDir) ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2, 2) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList _ArrayDisplay($aList) ; This is a loop that runs from 1 to the number of items listed in the first element of the returned array For $i = 1 To $aList[0] If $sFileRead = $sRoot & "\" & $aList[$i] Then _filewritelog ($log, "Deleting, " & $sFileRead) EndIf Next FileClose($hFileOpen)
  5. Sure: (It is based on a script from the forum - ?do=embed' frameborder='0' data-embedContent>) #include <Array.au3> #include <File.au3> #include <Date.au3> ; ***** Create local logs $log = FileOpen (@ScriptDir & "\masterlog.log",2+256) _FileWriteLog ($log,"*********************STARTING OPERATIONS*********************") ; put the root in a variable $sRoot = (@ScriptDir) ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2, 2) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList _ArrayDisplay($aList) ; This is a loop that runs from 1 to the number of items listed in the first element of the returned array For $i = 1 To $aList[0] ; For each folder, get the modified date/time and store its individual parts in array $aDate $aDate = FileGetTime($sRoot & "\" & $aList[$i], 0, 0) ; FileGetTime("filename" [, option [, format]]) ; Look at what FileGetTime() puts into $aDate ;_ArrayDisplay($aDate) ; Build the properly formatted date string for _DateDiff()'s needs $sDate = $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2] ;0 index stores the year, 1 index stores month, 2 index stores day ; Look at what we made into $sDate ;msgbox(0,"Check Output", $sDate) ; Use _DateDiff() to see if the difference is greater than 90 days, and if it's true, then delete (for now just log) the folder and all its subfolders If _DateDiff("D", $sDate, _NowCalcDate()) > 0 Then _FileWriteLog ($log,$sRoot & "\" & $aList[$i] & " " & "| Date Modified: " & $sDate, 1) Next _FileWriteLog ($log,"*********************Script Completed Successfully*********************")
  6. Hi everyone, sorry to re-post a portion of a code that I asked about only a short while ago, but I'm still learning the ropes and trying to make the script work. The main goal of my script it to delete folders that are older than 90 days but only in a certain depth. So for example, if this is the path: "c:userstest" - I only need to check the date modified of the folders under "test" directory and delete those folders that are older than 90 days. By using _FileListToArrayRec and -2 Negative integer - I get an array of the subfolders in the specified depth that I require. But I also get back everything else (-1 depth and 0 depth) _FileListToArrayRec ($sRoot, "*", 2, -2, 2) So the array I get is: c: c:users c:userstest My question would be - how do I only end up with the -2 depth (c:userstest) so that I can only check the date modified of those folders and delete them? Thanks!
  7. Ah! I had a feeling it'll be something to do with the trailing just didn't know where. Thanks a lot Melba23!! I appreciate your help.
  8. Hi there! I am trying to modify a script (based on a script that I found in the forum - '?do=embed' frameborder='0' data-embedContent>>) that goes through a list of folders using _FileListToArrayRec, but when I try to retrieve the "modified date" of the folderd for my log, I keep getting a message: (27) : ==> Subscript used on non-accessible variable.: $sDate = $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2] $sDate = $aDate^ ERROR I understand that there is an issue with retrieving the details from the array, but I can't quite figure out where my problem is. I Wonder if anyone can help me identify the problem? Thanks!! #include <Array.au3> #include <File.au3> #include <Date.au3> ; ***** Create local logs $log = FileOpen (@ScriptDir & "\masterlog.log",2+256) _FileWriteLog ($log,"*********************STARTING OPERATIONS*********************") ; put the root in a variable $sRoot = (@ScriptDir) ; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList Global $aList = _FileListToArrayRec ($sRoot, "*", 2, 0) ; _FileListToArray("path" [, "Filter" [, Flag]]) ; Look at what _FileListToArray() puts into $aList _ArrayDisplay($aList) ; This is a loop that runs from 1 to the number of items listed in the first element of the returned array For $i = 1 To $aList[0] ; For each folder, get the modified date/time and store its individual parts in array $aDate $aDate = FileGetTime($sRoot & $aList[$i], 0, 0) ; FileGetTime("filename" [, option [, format]]) ; Look at what FileGetTime() puts into $aDate _ArrayDisplay($aDate) ; Build the properly formatted date string for _DateDiff()'s needs $sDate = $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2] ;0 index stores the year, 1 index stores month, 2 index stores day ; Look at what we made into $sDate ;msgbox(0,"Check Output", $sDate) ; Use _DateDiff() to see if the difference is greater than 90 days, and if it's true, then delete (for now just log) the folder and all its subfolders If _DateDiff("D", $sDate, _NowCalcDate()) > 90 Then _FileWriteLog ($log,$sRoot & $aList[$i] & " " & $sDate, 1) Next _FileWriteLog ($log,"*********************Script Completed Successfully*********************")
  9. Thank you both! SpudW2k's suggestion did the trick and now it's back to work
  10. Hello, I am trying to add the following parameters to Robocopy embedded in an the Autoit script below: /S /COPY:DT /R:4 /LOG+:"C:Script.log" Any suggestions how to add it? Thanks in advance! RunWait(@ComSpec & ' /k ' & 'robocopy.exe "' & $SR1 & '" "' & $DS1 & '" ' & $PLC, @SystemDir)
  11. Hi, I'm writing a script that will check if PowerPoint process is running on a remote computer. I know how ro check it locally, Any idea how to check on a remote computer ? Thanks!
  12. Sorry. I had a feeling that just one line of code might be too vague... Thanks for your help, I found GUICtrlCreateInput to do the trick.
  13. Hello, I have a script for a GUI utility, that is opened from a user's computer and shows his IP, computer name etc. What I would like to do is to copy the result of the GuiCtrlCreateLabel output, so I could paste it somewhere else. Below is the code. Any help would be appreciated. Thanks in advance. $Button_14 = GuiCtrlCreateLabel("IP addresses:" & @CRLF & " " & @IPAddress1, -200, 10, 200)
  14. That should it... Thanks!
  15. Hello! I'm trying to create a folder on a server using: $Folder = InputBox("Test", "Please enter folder name", "") $dir = DirCreate("\\server-02\c$\" & $Folder) I want to run this command with some sort of "runas" and use different credentials with the following variables: $sUserName = "jsmith" $sPassword = "comp" Any idea? Thanks in advance!
×
×
  • Create New...