Page 1 of 1

Transfer Files with Current Date

Posted: 20 Oct 2010 07:40
by vvicin01
I created a dos command to transfer files to another server (ftp). What I want to do is limit the transfer only to files with the current date.

For example, I do a mput with the extension of *.zip:
mput E:\FOLDER\SUBFOLDER\exports\*.zip

How do I only select the *.zip files with current date.

Thank you.

Re: Transfer Files with Current Date

Posted: 20 Oct 2010 11:27
by aGerman
Hmm, not easy because it depends on the format settings for the date value.
Maybe you could write a FTP file using batch that contains the zip files behind several PUT commands.
Please try if the following batch file would return all todays zip files:

Code: Select all

@echo off &setlocal
for %%a in (E:\FOLDER\SUBFOLDER\exports\*.zip) do (
  for /f "tokens=1,2*" %%b in ("%%~ta %%~a") do (
    if "%%b"=="%date%" echo "%%d"
  )
)
pause


Regards
aGerman

Re: Transfer Files with Current Date

Posted: 20 Oct 2010 18:20
by ghostmachine4
Again, when dealing with dates, use vbscript or other programming languages that is able to handle dates well.. not batch

here's a vbscript to find files of today's date

Code: Select all

Set objFS = CreateObject( "Scripting.FileSystemObject" )
strFolder=WScript.Arguments(0)
N=Now
yr=Year(N)
mth=Month(N)
wday=Day(N)
Set objFolder = objFS.GetFolder(strFolder)
s=""
For Each strFile In objFolder.Files
   strFileName = strFile.Name
   If objFS.GetExtensionName(strFile) = "zip" Then
      strModDate = strFile.DateLastModified   
      strModYr = Year(strModDate)
      strModMth = Month(strModDate)
      strModDay = Day(strModDate)      
      If strModYr&strModMth&strModDay = yr&mth&wday Then
         WScript.Echo "mput "& strFileName   
      End If
   End If    
Next


usage

Code: Select all

C:\test> cscript //nologo myscript.vbs c:\test  > files_to_upload.txt


Then you can use files_to_upload.txt with your FTP client.

I would still recommend using a real programming language.

Re: Transfer Files with Current Date

Posted: 21 Oct 2010 16:26
by aGerman
ghostmachine4 wrote:Again, when dealing with dates, use vbscript or other programming languages that is able to handle dates well.. not batch

Normaly I would agree with you, but in this case we have a good chance that you would find the same date format in %date% and in %%~ta. Now we could compare it directly, regardless which date format is defined in the registry.
But you're right, VBScript is much better because it can handle date values.

Regards
aGerman