Hi, all!
I need to fetch (using ftp) a file from server to a directory on our server
In our directory are all the previous files
They are named like …XX010.dat, XX011.dat
File comes with original name ABC.dat
How do I change the name like this:
the next file must be renamed like XX012.dat
Thanks,
Ilpo
naming a file in a certain way
Moderator: DosItHelp
Re: naming a file in a certain way
You count the numbers and rename the file that is downloaded.
The set /a command can add one to the highest number
but the entire task is dependent on the actual names - because parsing the names is part of the job.
The set /a command can add one to the highest number
but the entire task is dependent on the actual names - because parsing the names is part of the job.
Re: naming a file in a certain way
Hi, folks!
I was wondering how to get rid of this manual renaming (SET /P and so on).
It would be best if it all could be done automatically within this batch:
(local is the place where renamed files are left, but the next phase needs
that new name.)
@ECHO OFF
setlocal
dir XYZ0*.dat
SET /P file=Give next number like 0257:
REM if exist XX%file%.dat goto run
REM get file with ftp if there is one
ECHO open 190.xx.xxx.x>ftp1.ini
ECHO user>>ftp1.ini
ECHO passwd>>ftp1.ini
ECHO cd inbox>>ftp1.ini
ECHO get ABC%file% XYZ%file%.dat>>ftp1.ini
ECHO bye>>ftp1.ini
ftp -s:ftp1.ini
if not exist ABC%file%.dat goto miss
rem if exist ABC%file%.dat goto run
goto run
:miss
ECHO There is no ABC%file%.dat.
goto end
:run
ECHO open serverX>ftp2.ini
ECHO user>>ftp2.ini
ECHO passwd>>ftp2.ini
ECHO cd m3server>>ftp2.ini
ECHO put XYZ%file%.dat XYZ%file%.dat>>ftp2.ini
ECHO bye>>ftp2.ini
ftp -s:ftp2.ini
:end
Thanks!
Ilpo
I was wondering how to get rid of this manual renaming (SET /P and so on).
It would be best if it all could be done automatically within this batch:
(local is the place where renamed files are left, but the next phase needs
that new name.)
@ECHO OFF
setlocal
dir XYZ0*.dat
SET /P file=Give next number like 0257:
REM if exist XX%file%.dat goto run
REM get file with ftp if there is one
ECHO open 190.xx.xxx.x>ftp1.ini
ECHO user>>ftp1.ini
ECHO passwd>>ftp1.ini
ECHO cd inbox>>ftp1.ini
ECHO get ABC%file% XYZ%file%.dat>>ftp1.ini
ECHO bye>>ftp1.ini
ftp -s:ftp1.ini
if not exist ABC%file%.dat goto miss
rem if exist ABC%file%.dat goto run
goto run
:miss
ECHO There is no ABC%file%.dat.
goto end
:run
ECHO open serverX>ftp2.ini
ECHO user>>ftp2.ini
ECHO passwd>>ftp2.ini
ECHO cd m3server>>ftp2.ini
ECHO put XYZ%file%.dat XYZ%file%.dat>>ftp2.ini
ECHO bye>>ftp2.ini
ftp -s:ftp2.ini
:end
Thanks!
Ilpo
Re: naming a file in a certain way
Hi folks!
I need to specify my case.
local is the place where files are left and where the batch is.
I was thinking if it's possible to automate that renaming process - for now it has been made manually?
It's the second phase that actually needs that new name.
So how to rename (SET /P phase) file within the automated batch?
Batch:
@ECHO OFF
setlocal
dir XYZ0*.dat
SET /P file=Give next number like 0257:
REM if exist ABC%file%.dat goto run
REM get file with ftp if there is one
ECHO open 190.xx.xxx.x>ftp1.ini
ECHO user>>ftp1.ini
ECHO passwd>>ftp1.ini
ECHO cd inbox>>ftp1.ini
ECHO get ABC%file% XYZ%file%.dat>>ftp1.ini
ECHO bye>>ftp1.ini
ftp -s:ftp1.ini
if not exist ABC%file%.dat goto miss
rem if exist ABC%file%.dat goto run
goto run
:miss
ECHO There is no ABC%file%.dat.
goto end
:run
ECHO open serverX>ftp2.ini
ECHO user>>ftp2.ini
ECHO passwd>>ftp2.ini
ECHO cd m3server>>ftp2.ini
ECHO put XYZ%file%.dat XYZ%file%.dat>>ftp2.ini
ECHO bye>>ftp2.ini
ftp -s:ftp2.ini
:end
Thanks,
Ilpo
I need to specify my case.
local is the place where files are left and where the batch is.
I was thinking if it's possible to automate that renaming process - for now it has been made manually?
It's the second phase that actually needs that new name.
So how to rename (SET /P phase) file within the automated batch?
Batch:
@ECHO OFF
setlocal
dir XYZ0*.dat
SET /P file=Give next number like 0257:
REM if exist ABC%file%.dat goto run
REM get file with ftp if there is one
ECHO open 190.xx.xxx.x>ftp1.ini
ECHO user>>ftp1.ini
ECHO passwd>>ftp1.ini
ECHO cd inbox>>ftp1.ini
ECHO get ABC%file% XYZ%file%.dat>>ftp1.ini
ECHO bye>>ftp1.ini
ftp -s:ftp1.ini
if not exist ABC%file%.dat goto miss
rem if exist ABC%file%.dat goto run
goto run
:miss
ECHO There is no ABC%file%.dat.
goto end
:run
ECHO open serverX>ftp2.ini
ECHO user>>ftp2.ini
ECHO passwd>>ftp2.ini
ECHO cd m3server>>ftp2.ini
ECHO put XYZ%file%.dat XYZ%file%.dat>>ftp2.ini
ECHO bye>>ftp2.ini
ftp -s:ftp2.ini
:end
Thanks,
Ilpo
Re: naming a file in a certain way
I gather you just want your code below to increment the number in the file variable.
You parse the brief directory listing in a for loop and extract the number, and add one to it.
As mentioned in my last post, the filenames are important because the way the listing is parsed depends on the actual filename format.
See here: viewtopic.php?f=3&t=6108
Code: Select all
@ECHO OFF
setlocal
dir XYZ0*.dat
SET /P file=Give next number like 0257:
You parse the brief directory listing in a for loop and extract the number, and add one to it.
As mentioned in my last post, the filenames are important because the way the listing is parsed depends on the actual filename format.
See here: viewtopic.php?f=3&t=6108