Transfer Files with Current Date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vvicin01
Posts: 1
Joined: 20 Oct 2010 07:08

Transfer Files with Current Date

#1 Post by vvicin01 » 20 Oct 2010 07:40

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Transfer Files with Current Date

#2 Post by aGerman » 20 Oct 2010 11:27

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

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Transfer Files with Current Date

#3 Post by ghostmachine4 » 20 Oct 2010 18:20

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Transfer Files with Current Date

#4 Post by aGerman » 21 Oct 2010 16:26

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

Post Reply