Computing.Net > Forums > Programming > Move files with date as parameter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Move files with date as parameter

Reply to Message Icon

Name: nagendraG
Date: June 16, 2008 at 08:56:30 Pacific
OS: xp
CPU/Ram: intel core duo
Product: 2002
Comment:

Hi All,

I have to move the files from one folder to other folder based on the date.

For example in Folder A i will have .txt from jan 2007.I need to use a .bat script to which i should pass the date as parameter (YYYYMMDD is the date format ).., to move files for that particular date.

If for 20080514 i have 14 files i will pass this date as parameter to the .bat script which should move all the 14 files from c:\old to c:\new folder .

Hope i am clear...

Pls suggest how can i write .bat for this requirement.

Thanks,
Nagendra



Sponsored Link
Ads by Google

Response Number 1
Name: nagendraG
Date: June 16, 2008 at 08:58:31 Pacific
Reply:

My files will have timestamped attached as below.
abc_20080401112344.txt
abc_20080517135422.txt

Thanks,
Nagendra


0

Response Number 2
Name: klint
Date: June 16, 2008 at 10:32:07 Pacific
Reply:

@echo off
set /p dat=Enter date as YYYYMMDD:
copy c:\old\abc_%dat%*.txt c:\new


0

Response Number 3
Name: nagendraG
Date: June 16, 2008 at 12:59:25 Pacific
Reply:

Thanks for your quick response klint...

But i need to pass the date as parameter to the batch file..say for example my bat script is test.bat...then i have to pass the date as below.
test.bat 20080616
because the date is a dynamic one generated by our source application...we will parametrize the date value so that we can schedule the job.

Pls suggest a way for this.

Thanks,
Nagendra


0

Response Number 4
Name: Shr0Om
Date: June 16, 2008 at 13:41:41 Pacific
Reply:

This should do the trick (test.bat 20080616)

@echo off
set dat=%1%
copy c:\old\abc_%dat%*.txt c:\new


0

Response Number 5
Name: Ravi_varma
Date: June 17, 2008 at 02:05:55 Pacific
Reply:

I tried to move the files between share drives i.e from one share drive to another in the same network using the batch script but it is giving an error file not found

@echo off
pushd \\rrh\customer

set dat=%1%

copy \\rrh\customer\abc_%dat%*.txt
\\rrh\customer\backup


and i have passed the date as parameter to the batch as follows

test.bat 20080615

it says file not found..but the files are present in the share drive

thx,
Ravi


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: June 18, 2008 at 04:11:03 Pacific
Reply:

No need to set dat to command line parameter.

[And "set dat=%1%" won't due it.]

just:

copy abc_%1*.txt x:\blabla


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: Shr0Om
Date: June 19, 2008 at 09:05:45 Pacific
Reply:

Mechanix2Go:

Yup,i guess set dat=.. is unnecessary, but:
set dat=%1% works fine here tho (Windows XP)


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Move files with date as parameter

moving files with a .bat www.computing.net/answers/programming/moving-files-with-a-bat/17109.html

Batch to move file by sysdate www.computing.net/answers/programming/batch-to-move-file-by-sysdate/14939.html

move files with same name www.computing.net/answers/programming/move-files-with-same-name/18856.html