Computing.Net > Forums > Programming > Append a number to filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Append a number to filename

Reply to Message Icon

Name: remgu
Date: September 26, 2007 at 07:16:03 Pacific
OS: XP
CPU/Ram: 3.4
Product: Clone
Comment:

I have a batch file that FTPs a text file from a server to the user's PC. However sometimes the file is needed to be FTPed more than once a day. When we attempt to FTP it again, since there is a file with the same name already in that directory we get the following:

A duplicate file name exists, or the file
cannot be found.
Press any key to continue . . .

How can I tell the batch file to add one digit to the end of the file name so that we don't have this duplicate issue.

For example:

09-20-07file1.txt
09-20-07file2.txt
09-20-07file3.txt
...etc.

That is a simplified example; in reality the file names would look more like this:

audit.dump.%dumpdate%.LK%dumptid%001.txt
audit.dump.%dumpdate%.LK%dumptid%002.txt
audit.dump.%dumpdate%.LK%dumptid%003.txt
...etc.

Here is the part of the code that is relevant:

~

:LOOP1
Echo Enter the TID (xxxxxx) for the Audit Dump.
Echo.
Set /P dumptid= ^>
Echo.
Echo Enter the Date (yy-mm-dd) for the Audit Dump.
Echo.
Set /P dumpdate= ^>
Echo.
Echo.
Echo The Audit Dump's TID and Date that you entered are %dumptid% and %dumpdate%.
Echo Press Y or y and then ENTER if correct or press ENTER to retry.
Echo.
Set /P answ= ^>
Echo.
Echo.
Echo.
If /I not "%answ%."=="Y." GoTo :LOOP1
cd c:\ftp_temp
> latest.ftp.request.txt echo o %qastratusip%
>> latest.ftp.request.txt echo %qastratususername%
>> latest.ftp.request.txt echo %qastratuspassword%
>> latest.ftp.request.txt echo bin
>> latest.ftp.request.txt echo cd audit_dumps
>> latest.ftp.request.txt echo get %dumptid%.%dumpdate%.prt
>> latest.ftp.request.txt echo bye
ftp -s:latest.ftp.request.txt

REM *****************Start of Last FTP Request Time Stamp***************
echo @prompt set date=$d$_set time=$t$h$h$h > {a}.bat
%comspec% /e:2048 /c {a}.bat > {b}.bat
for %%v in ({b}.bat del) do call %%v {?}.bat
echo %date% %time% >> latest.ftp.request.txt
REM *****************End of Last FTP Request Time Stamp*****************

rename %dumptid%.%dumpdate%.prt audit.dump.%dumpdate%.LK%dumptid%.txt
Set dumptid=
Set dumpdate=
Set answ=
Pause
goto start

~

Thanks,
REMGU



Sponsored Link
Ads by Google

Response Number 1
Name: tonysathre
Date: September 26, 2007 at 16:27:10 Pacific
Reply:

You could do a GET to download the file first, then check if the filenames are the same. If they are, then append a number with this:

for /l %%n in (1,1,99) do (
rename downloaded_file downloaded_file%%n
)

Then, PUT the new file.

There's probably a better way to do it though , so I'll mess around with it.


"Computer security." — Oxymoron


0

Response Number 2
Name: Mechanix2Go
Date: September 27, 2007 at 02:28:00 Pacific
Reply:

There are several ways of discovering ;ast used suffix. Am correct in thinkiing all the files of interest have the extension txt?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 3
Name: remgu
Date: September 27, 2007 at 05:22:49 Pacific
Reply:

Hi M2, you actually helped me out with the original batch file. Yes, the file FTP'ed is converted from a .prt to a .txt.

Thanks,
REMGU


0

Response Number 4
Name: Mechanix2Go
Date: September 28, 2007 at 07:57:15 Pacific
Reply:

I got the zip. II won't get to work on iit until tomorrow.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 5
Name: remgu
Date: September 28, 2007 at 10:22:39 Pacific
Reply:

Thanks I appreciate it.

Thanks,
REMGU


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: October 1, 2007 at 01:15:08 Pacific
Reply:

I'm lost. I think I've mixed two threads.


=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

conversion of bat to exe Batch file to move files ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Append a number to filename

Append a number to filename www.computing.net/answers/programming/append-a-number-to-filename/15802.html

append a number tonew file created www.computing.net/answers/programming/append-a-number-tonew-file-created/15765.html

append creation date to filename www.computing.net/answers/programming/append-creation-date-to-filename/16017.html