Question Locked

FTP / VBScript

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi All

I have a problem with a customer that continually sends us files with a comma in the filename but will not change their conventions. The comma isn't always in the same place though. And most of the time not there at all. I currently have a dos batch file that is run by the ftp server when a file is uploaded, but naturally it's missing these files, can anyone suggest a way of removing the commas? I'd like to use VBS but I'm rubbish at it - trying to learn again though. I'm using ncftp to do the actual file transfer to another internal ftp server (it works and is very fast).

Thanks

3 replies

by lowlands

Do I understand it correctly that the filename itself has a comma in it? So something like text,file.txt.

Second question, what does the batch file on your ftp server do?

And this little script would rename any files with 1 comma in it to the same name, but without the comma. This example checks all temp dirs on the system, so change that to whatever directory your files are in.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\TEMP\\'")

For Each objFile in colFiles
If instr(objFile.Name, ",") <> 0 Then

arrFileName = Split(objFile.Name, ",")
strNewFileName = arrFileName(0) & arrFileName(1)
Wscript.Echo objFile.Name
wscript.echo strNewFileName
errResult = objFile.Rename(arrFileName(0) & arrFileName(1))

end if
Next

This discussion is closed to new replies.