Computing.Net > Forums > Programming > Batch to compare and move files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch to compare and move files

Reply to Message Icon

Name: jpcallicott
Date: October 20, 2005 at 05:59:29 Pacific
OS: Win 2k3 server
CPU/Ram: Intel / lots
Comment:


Hello,

I'm hoping someone can help me with a problem. I need to have a batchfile rename a file with the current date, and move the file to a corrisponding 'month' folder. How do I get the batch to look at the filename and know what month-folder to put the file in?



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: October 20, 2005 at 14:10:55 Pacific
Reply:

Hi
A few questions.

1, What doe's 'echo %Date%' produce on your system.
2, In what format do you want the file named.
3, How are your Month Dirs named.


0

Response Number 2
Name: jpcallicott
Date: October 20, 2005 at 21:10:26 Pacific
Reply:

okay,

1. I get 'Fri 10/21/2005' on the echo %date%

2. I just need the file named for the current date, however it looks.

3. I can name the month-folders anything.

I'm hoping to have this scheduled, so I want it to be as automatic as possible.


0

Response Number 3
Name: Mechanix2Go
Date: October 20, 2005 at 22:55:20 Pacific
Reply:

Hi jp,

In the BAT below I set var D to a date like yours. {because my layout is different.]

You can modify the second line to:

set D=%DATE%

:: ren2MM.bat
@echo off > test1.txt

set D=Fri 10/21/2005

set newNAME=%D:~10,4%%D:~4,2%%D:~7,2%
set MM=%D:~4,2%

ren test1.txt %newNAME%.txt
if not exist %MM% md %MM%
move %newNAME%.txt %MM%
:: DONE


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

M2


0

Response Number 4
Name: jpcallicott
Date: October 25, 2005 at 04:20:27 Pacific
Reply:

Thank you so much,

This is a real life-saver. Is there a book or reference out there where I can learn this? I'm sure I'll need to be writing other batch files in the future.


0

Response Number 5
Name: Mechanix2Go
Date: October 28, 2005 at 04:26:50 Pacific
Reply:

Thanks for letting us know that helped.

There are plenty of samples and tutorials out there; I don't have a link handy.

I find it difficult to follow others' code.

Try writing something simple ]or use an existing script] and then modify it. When you get stuck, ask for specific help.

Any question about what the script above is doing?


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

M2


0

Related Posts

See More


Reply to Message Icon

GWBasic to VB number conv... Autorun If Statement



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: Batch to compare and move files

Batch to parse dirs move files www.computing.net/answers/programming/batch-to-parse-dirs-move-files/17645.html

Batch to compare files' size www.computing.net/answers/programming/batch-to-compare-files-size/17428.html

Batch file to rename and move www.computing.net/answers/programming/batch-file-to-rename-and-move/12958.html