Move from FTP and count in Target folder automated

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#121 Post by aaksar » 06 Dec 2012 11:29

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Move from FTP and count in Target folder automated

#122 Post by foxidrive » 06 Dec 2012 11:43

Did you tell anyone before now that your filenames have dates on them?

Just wondering. This has gone on to 8 pages now...

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Move from FTP and count in Target folder automated

#123 Post by Squashman » 06 Dec 2012 12:41

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.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#124 Post by abc0502 » 06 Dec 2012 14:01

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
with 2>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.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#125 Post by aaksar » 06 Dec 2012 22:41

ok, thanks,
I will try to update the script to compare file name without date.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#126 Post by abc0502 » 07 Dec 2012 06:46

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:

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.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#127 Post by aaksar » 07 Dec 2012 07:27

ok will test it, thanks buddy

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#128 Post by aaksar » 10 Dec 2012 23:04

ok, my file name is
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"

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#129 Post by abc0502 » 11 Dec 2012 01:56

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"

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.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#130 Post by aaksar » 11 Dec 2012 22:28

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?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#131 Post by abc0502 » 12 Dec 2012 00:54

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?

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#132 Post by aaksar » 12 Dec 2012 02:17

file always come with new date... and format is yyyymmdd
LIKE TODAY " today date/previous day date"
tmrw" today_date-1)

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#133 Post by aaksar » 12 Dec 2012 02:18

output

Code: Select all

Wed 12/12/2012

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#134 Post by abc0502 » 12 Dec 2012 03:35

aaksar wrote:file always come with new date... and format is yyyymmdd
LIKE TODAY " today date/previous day date"
tmrw" today_date-1)
don't understand ?
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 :?

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#135 Post by aaksar » 12 Dec 2012 03:51

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.

Post Reply