Jump to content

Help with FileCopy and FileMove


PhilBall
 Share

Recommended Posts

Hello

I have written a script that is designe to read the filename and move it a to a directory and sub directory based on it's filename.

The beginning of a file has a 3 digit shortcode and the end of a file has another code starting with either an M, W, F or T and then two digits.

When I run the script, it creates the folder and subfolder, but then does not move the file.

I have tried using the #RequireAdmin keyword but that then will not find the file in the first place.

Here is my script:

$SC = InputBox("Move PDF Files", "Enter Shortcode")
iF @error = 1 Then
MsgBox(0,"Exiting Move PDF Files", "This program is closing, none of your PDFs have been moved")
Exit
EndIf
If $SC = "" Then
MsgBox(0,"ERROR", "You did not enter a shortcode, try again")
$SC = InputBox("Move PDF Files", "Enter Shortcode")
If @error = 1 Then
  MsgBox(0,"Exiting Move PDF Files", "This program is closing, none of your PDFs have been moved")
  Exit
EndIf
EndIf
$File_Name = "S:\SHARED\EXCEL\PDF\" & $SC & "*.PDF"
$search = FileFindFirstFile($File_Name)
; Check if the search was successful
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
    ;MsgBox(4096, "File:", $file)
$tail = StringRight($file,7)
$freq = Stringleft($tail,3)
$NumTest = StringLEFT($tail,1)
 
if $NumTEST = "M" OR $NumTEST = "W" OR $NumTEST = "T" OR $NumTEST = "F" Then
;MsgBox(4096,"Freq",$freq)
MsgBox(4096,"FILENAME","S:\SHARED\EXCEL\PDF\PBTEST\" & $SC & "\" & $freq & "\" & $file)
;$FileAtt = FileGetAttrib ("S:\SHARED\EXCEL\PDF\PBTEST\" & $SC & "\" & $freq & "\" & $file )
;If @error Then
    ;MsgBox(4096,"Error", "Could not obtain attributes.")
;Else
;MsgBox(4096,"Attributes",$FileAtt)
;EndIf
FileCopy ($file, "S:\SHARED\EXCEL\PDF\PBTEST\" & $SC & "\" & $freq & "\" & $file,8)
  If @error = 0 Then
  MsgBox(0,"Error", "file did not move")
EndIf
EndIf
WEnd
; Close the search handle
FileClose($search)

Thanks, Phil

Link to comment
Share on other sites

Try this. I amended the first bit to make it more user friendly so you dont have to restart the program in the event of entry error.

The failure to copy was the incomplete path in the FileCopy() command, which I amended to FileMove() as you said you wanted to move it. Do you really want all those levels in the new path...it's a bit messy.

Do
$SC = InputBox("Move PDF Files", "Enter Shortcode:", "", "", 250, 125)
If @error = 1 Then
  MsgBox(0,"Exiting Move PDF Files", "This program is closing, none of your PDFs have been moved")
  Exit
EndIf
If $SC = "" Then
  MsgBox(0,"ERROR", "You did not enter a shortcode, try again")
  ContinueLoop
EndIf
$File_Name = "S:\SHARED\EXCEL\PDF\" & $SC & "*.PDF"
$search = FileFindFirstFile($File_Name)
If $search = -1 Then
  MsgBox(0, "Error", "No files/directories matched the search pattern")
EndIf
Until $SC <> "" And $search <> -1
 
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
$tail = StringRight($file,7)
$freq = Stringleft($tail,3)
$NumTest = StringLEFT($tail,1)
if $NumTEST = "M" OR $NumTEST = "W" OR $NumTEST = "T" OR $NumTEST = "F" Then
  MsgBox(4096,"FILENAME","S:\SHARED\EXCEL\PDF\PBTEST\" & $SC & "\" & $freq & "\" & $file)
  FileMove("S:\SHARED\EXCEL\PDF\" & $file, "H:\SHARED\EXCEL\PDF\PBTEST\" & $SC & "\" & $freq & "\" & $file, 8)
EndIf
WEnd

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...