Move from FTP and count in Target folder automated
Moderator: DosItHelp
Re: Move from FTP and count in Target folder automated
And one more thing, if the file name coming with date then what will happen, its not feasable to go evertime in file.lst file and change the date,
What do u say, so can we skip the date while comparing file name.
This situation is in zip file currently, but in future it can be with otherfiles also from diff ftp server
What do u say, so can we skip the date while comparing file name.
This situation is in zip file currently, but in future it can be with otherfiles also from diff ftp server
Re: Move from FTP and count in Target folder automated
Did you tell anyone before now that your filenames have dates on them?
Just wondering. This has gone on to 8 pages now...
Just wondering. This has gone on to 8 pages now...
Re: Move from FTP and count in Target folder automated
foxidrive wrote:Did you tell anyone before now that your filenames have dates on them?
Just wondering. This has gone on to 8 pages now...
9 on my view.
This has gone way beyond the scope of free help if you ask me.
Re: Move from FTP and count in Target folder automated
aaksar wrote:Ok, so seems like script is done.
If we can put if condition when we r deleting/ unzip the zip files,
So it wont give error zip file is not there,
Try changing the >nul at the end of
Code: Select all
"%zip_program%" x -y "%~6\*.%zipped%" -o"%~6" >nul
this should remove the errors
about the date of the files, you should mentioned that in earlier, batch files is not so flexible when it comes to changing just a part of the whole code,
I guess you will have to update the FILE.lst every day, and the batch will try whole day till it download your files.
Re: Move from FTP and count in Target folder automated
ok, thanks,
I will try to update the script to compare file name without date.
I will try to update the script to compare file name without date.
Re: Move from FTP and count in Target folder automated
About the date in your files,
IF there is a separator between the file name and the date and the date is after the name this small modification should work fine,
Replace this code:
With
Just make sure to modify the "delims" and the separator between %%a and %%b in the variable "name" in 3rd line
But if there is no separator between the file name and the dates it will be required to change a big amount of the code or add more codes to fix that
And note that this will just check for the name in your local folder that mean if there is old files in local folders with same name but different dates it won't make any difference and the batch won't download the new files, so every day you run the batch make sure you moved the files from the previous day or it will be a mess.
IF there is a separator between the file name and the date and the date is after the name this small modification should work fine,
Replace this code:
Code: Select all
For /F "delims=" %%a in ('Type "%~1"') Do (
For /F "delims=" %%b in ('Type "%temp%\%~8\server_list.lst"') Do (
Set "sf=%%b"
setlocal enabledelayedexpansion
IF "%%a"=="!sf:~1,-1!" (
IF NOT EXIST "%~6\%%b" echo get %%b>>"%temp%\%~8\commands_2.ftp"
)
endlocal
)
)
With
Code: Select all
For /F "delims=" %%A in ('Type "%~1"') Do (
For /F "tokens=1* delims= " %%a in ('Type "%temp%\%~8\server_list.lst"') Do (
set "name=%%a %%b"
Set "sf=%%a"
setlocal enabledelayedexpansion
IF "%%~nA"=="!sf:~1!" (
IF EXIST "!name:~1,-1!" echo !name!>>"%temp%\%~8\commands_2.ftp"
)
endlocal
)
)
Just make sure to modify the "delims" and the separator between %%a and %%b in the variable "name" in 3rd line
But if there is no separator between the file name and the dates it will be required to change a big amount of the code or add more codes to fix that
And note that this will just check for the name in your local folder that mean if there is old files in local folders with same name but different dates it won't make any difference and the batch won't download the new files, so every day you run the batch make sure you moved the files from the previous day or it will be a mess.
Re: Move from FTP and count in Target folder automated
ok will test it, thanks buddy
Re: Move from FTP and count in Target folder automated
ok, my file name is
XY_250_ABC_XYZ_20121005.zip
name always be constant. so the code will be like this
IF i Change the delims then it wont take the next file name from the file, as you are checking for double quotes"
XY_250_ABC_XYZ_20121005.zip
name always be constant. so the code will be like this
Code: Select all
For /F "delims=" %%A in ('Type "%~1"') Do (
For /F "tokens=1* delims= " %%a in ('Type "%temp%\%~8\server_list.lst"') Do (
set "name=%%a "_" %%b"
Set "sf=%%a"
setlocal enabledelayedexpansion
IF "%%~nA"=="!sf:~1!" (
IF EXIST "!name:~1,-1!" echo !name!>>"%temp%\%~8\commands_2.ftp"
)
endlocal
)
)
IF i Change the delims then it wont take the next file name from the file, as you are checking for double quotes"
Re: Move from FTP and count in Target folder automated
That is now easier, the date will always be the last 9 digits "8 digits as the date, month & year + _", without the extension of course.
SO when we compare the file names from the "FILE.lst1" with the names in "server_list.lst" we will remove these 9 digits from the server names and add the extension so it will always match the names in "FILE.lst1" files.
Also, note that when we take the name like this "SFname=%%~nb" it will remove the double qoutes so we won't need to do this again "!sf:~1,-1!"
This is the code, replace it in your "Code.bat"
This should work, try it.
SO when we compare the file names from the "FILE.lst1" with the names in "server_list.lst" we will remove these 9 digits from the server names and add the extension so it will always match the names in "FILE.lst1" files.
Also, note that when we take the name like this "SFname=%%~nb" it will remove the double qoutes so we won't need to do this again "!sf:~1,-1!"
This is the code, replace it in your "Code.bat"
Code: Select all
For /F "delims=" %%a in ('Type "%~1"') Do (
For /F "delims=" %%b in ('Type "%temp%\%~8\server_list.lst"') Do (
Set "SFname=%%~nb"
Set "SFext=%%~xb"
setlocal enabledelayedexpansion
IF "%%a"=="!SFname:~0,-9!!SFext!" (
IF NOT EXIST "%~6\%%b" echo get %%b>>"%temp%\%~8\commands_2.ftp"
)
endlocal
)
)
This should work, try it.
Re: Move from FTP and count in Target folder automated
Thanks Buddy,
Its working like charm,
If some files coming with date and some are not coming with Date then how will it identify whether it needs to remove last 8 Char?
Its working like charm,
If some files coming with date and some are not coming with Date then how will it identify whether it needs to remove last 8 Char?
Re: Move from FTP and count in Target folder automated
If some files coming with date and some are not coming with Date then how will it identify whether it needs to remove last 8 Char?
OK, Does these files always come in the same date it is dated with, like if to day is 12/5/2012 so the files will have 20120512 at the end when you download them?
IF the above is right, write this in your cmd window and post the output here in your next post.
Code: Select all
echo %date%
and tell me, the red numbers "20120512" are they the month or the day, i mean what is the format the date is written in?
Re: Move from FTP and count in Target folder automated
file always come with new date... and format is yyyymmdd
LIKE TODAY " today date/previous day date"
tmrw" today_date-1)
LIKE TODAY " today date/previous day date"
tmrw" today_date-1)
Re: Move from FTP and count in Target folder automated
output
Code: Select all
Wed 12/12/2012
Re: Move from FTP and count in Target folder automated
don't understand ?aaksar wrote:file always come with new date... and format is yyyymmdd
LIKE TODAY " today date/previous day date"
tmrw" today_date-1)
Do you mean, if to day 12/12/2012 so the files that you will download today will have that date.
and if downloading files tomorrow "13/12/2012" it will have that date ?
Advance your computer date 1 day ahead and try the command again, i don't know which 12 is the month

Re: Move from FTP and count in Target folder automated
see,
some files come with date like
XY_250_ABC_XYZ_20121005.zip (Format (YYYY-2012)(MM-10)(DD-05))
some file come without date like "abc.txt" or "xyz"(without extension)
If the date is coming in file name then everytime it will be different date
can be (today date-1) can be (today date-5)
so we should check if the name contains date then remove last 8 Char and add extension, otherwise same.
coz I am doing date validation at next step
i dont know its possible or not, but this is scenario.
some files come with date like
XY_250_ABC_XYZ_20121005.zip (Format (YYYY-2012)(MM-10)(DD-05))
some file come without date like "abc.txt" or "xyz"(without extension)
If the date is coming in file name then everytime it will be different date
can be (today date-1) can be (today date-5)
so we should check if the name contains date then remove last 8 Char and add extension, otherwise same.
coz I am doing date validation at next step
i dont know its possible or not, but this is scenario.