Hello,
I am attempting to upload files to specific folders based on their file names. For example:
C:\Files has:
File1.csv
File2.csv
File2more.csv
File3.csv
File3more.csv
File4.csv
The FTP site has folder that these need to upload to:
/File1/
/File2/
/File3/
/File4/
I figure that if I can parse the file name, I can put together a directory list. I can iterate through that list and upload the files accordingly. However, I'm not too sure what the ScriptFTP string functions would be that relate to MID, LEFT, RIGHT or INSTR from vbscript or PHP.
Any help would be appreciated. Thanks in advance!
-Aaron
I am attempting to upload files to specific folders based on their file names. For example:
C:\Files has:
File1.csv
File2.csv
File2more.csv
File3.csv
File3more.csv
File4.csv
The FTP site has folder that these need to upload to:
/File1/
/File2/
/File3/
/File4/
I figure that if I can parse the file name, I can put together a directory list. I can iterate through that list and upload the files accordingly. However, I'm not too sure what the ScriptFTP string functions would be that relate to MID, LEFT, RIGHT or INSTR from vbscript or PHP.
Any help would be appreciated. Thanks in advance!
-Aaron
Hello Aaron,
You can use the command TEXTCUT to get the chunk of the file name you need. For example:
You can use the command TEXTCUT to get the chunk of the file name you need. For example:
Code: Select all
# Change current local directory to C:\Files
$result=LOCALCHDIR("C:\Files")
# If it failed stop the script
IF($result!="OK")
  STOP
END IF
# Retrieve the C:\pim\outbox file listing
$result=GETLIST($list,LOCAL_FILES,"*.csv")
# If GETLIST failed stop the script
IF($result!="OK")
  STOP
END IF
# For each file in $list...
FOREACH $item IN $list
# Check that the filename has at least 8 characters
  # (4 for the name, one dot, and 3 for the extension)
IF(TEXTLENGTH($item)>=8)
# Get the first 4 characters of the file name
$dirname=TEXTCUT($item,1,4)
# Change current remote directory to a dir
    # which name is the first 4 characters of the
    # file to be uploaded
$result=CHDIR($dirname)
# If it failed stop the script
IF($result!="OK")
  STOP
END IF
# Upload the file
$result=PUTFILE($item)
# If it failed stop the script
IF($result!="OK")
  STOP
END IF
# return to the parent directory
$result=CHDIR("..")
# If it failed stop the script
IF($result!="OK")
  STOP
END IF
END IF
END FOREACH
Â
liked Script FTP? Try our other product Email Parser