Sign in to follow this  
Followers 0
Santana

File move

5 posts in this topic

Hi all,

I am trying to use the following code (from the help file) to move a set of text files from one directory to another

this example assumes that I have a set of files in a folder (file1.txt, file2.txt ... file5.txt). I want the script to search a folder and if the whole set (the five files) are notfound, it pauses for lets say 5 minutes and search the folder until all files are there. when all the files are found, I then want to move them where I want them.

any idea?

Thanks in advance.

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    if $file = "File1.txt" then
filemove(@scriptdir & "\$file", "c:\" & $file)
else
if $file = "File2.txt" then
filemove(@scriptdir & "\$file", "c:\" & $file)
;etc
end if
WEnd

FileClose($search)

Just another special date with a different challenge

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can use FileExists for your job

while bitand(FileExists(file1),...
sleep(100)
wend

It will wait while file of name file1 exists in the directory..

I think this can do your job..

Edited by Piyush

[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Share this post


Link to post
Share on other sites

it has also been my experience that while the Search handle created by FileFindFirstFile() is open, the files affected by it are write locked (can't delete) so you will have to create an array and then FileClose() the search handle in order to move them.


[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi all,

I had another project and am back to this issue. Well I thought about creating an array with the filenames + currentdate ($sJulDate for Julian Dates used to calculate date differences somewhere in the script)

Then, I would use the FileExists function to search for file names in the directory and if the file exists, I delete that element for the array. I then want to count the elements in the array which should be =0 if all the files where found. In that case, I will move all the files to another directory for processing. Otherwise,I will pause the script and re-run the function every 5 minutes per say until all files are found in the directory ( I cannot process the files unless I have the whole set).

I didn't understand the bidand() function so I thought the following code would do but got an error: => Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Any suggestion?

Thanks in advance.

Dim $aArray[8]
$aArray[0]="TRAN@AUD_" & $sJulDate
$aArray[1]="ALPHA@DI_" & $sJulDate
$aArray[2]="ALPHA@IN_" & $sJulDate
$aArray[3]="IP@XFER#_" & $sJulDate
$aArray[4]="OP@EXCEP_" & $sJulDate
$aArray[5]="BILLSUMC_" & $sJulDate
$aArray[6]="OP@XFER#_" & $sJulDate
$aArray[7]= "BILLSUMC_" & $sJulDate
for $a = 0 to UBound($aArray)
if FileExists($RootFolder & "\PFSrpts\" & $aArray[$a] ) = 1 Then
    _ArrayDelete($aArray, $a)
    endif
Edited by Santana

Just another special date with a different challenge

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi all,

I had another project and am back to this issue. Well I thought about creating an array with the filenames + currentdate ($sJulDate for Julian Dates used to calculate date differences somewhere in the script)

Then, I would use the FileExists function to search for file names in the directory and if the file exists, I delete that element for the array. I then want to count the elements in the array which should be =0 if all the files where found. In that case, I will move all the files to another directory for processing. Otherwise,I will pause the script and re-run the function every 5 minutes per say until all files are found in the directory ( I cannot process the files unless I have the whole set).

I didn't understand the bidand() function so I thought the following code would do but got an error: => Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Any suggestion?

Thanks in advance.

Dim $aArray[8]
$aArray[0]="TRAN@AUD_" & $sJulDate
$aArray[1]="ALPHA@DI_" & $sJulDate
$aArray[2]="ALPHA@IN_" & $sJulDate
$aArray[3]="IP@XFER#_" & $sJulDate
$aArray[4]="OP@EXCEP_" & $sJulDate
$aArray[5]="BILLSUMC_" & $sJulDate
$aArray[6]="OP@XFER#_" & $sJulDate
$aArray[7]= "BILLSUMC_" & $sJulDate
for $a = 0 to UBound($aArray)
if FileExists($RootFolder & "\PFSrpts\" & $aArray[$a] ) = 1 Then
    _ArrayDelete($aArray, $a)
    endif

Hi,

a simple change:

for $a = 0 to UBound($aArray)

to

for $a = 0 to UBound($aArray) - 1

should be the solution.

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0