|
Answer» Thank you in advance for any help with this.
As the name implies, I am a rookie with DOS so please bear with me. I have SEARCHED the forum for the last few days and have found pieces of of what I'm looking for, but have not been able to combine them into what I need.
What I need is a batch program that will do the following: 1. Select files all of the .txt files from folder 1 2. Add the date and time to the beginning of each of the selected filenames 3. Save the new files to folder 2 4. Remove the original files from folder 1
If there is a be sequence of steps, I'm open to suggestions. This process will be used to Archive text files of data that have been sent out via EDI. New .txt files are generated daily and will have the same file names as the day before.
I have seen the POST for Renaming a file to INCLUDE BOTH Date & Time Stamp, but it is only for one file. How do I get it to process all of the .txt files in the folder?
Thanks!
The for loop will work for you. Use the code you already found to name the file wrap it in a loop such as this:
Code: [Select]for /d %a in (\folder1\*.txt) do (
mv %a \folder2\newfilename.txt
)
REPLACE newfilename.txt with the filename you generated with the datetime stamp. Be careful to test this on a test directory - not the real data, plus you need a way to ensure the new files don't all have the same name. Thanks for the quick reply. I'm still struggling though for lack of understanding. Not quite sure how to "Wrap" in a FOR loop. Here is what I have:
@echo off
for /f "tokens=1-5 delims= " %%A in ( ' cscript //nologo TimeStamp.vbs ' ) do ( set dd=%%A set MM=%%B set YYYY=%%C set hh=%%D set mn=%%E )
if %dd% LEQ 9 set dd=0%dd% if %mm% LEQ 9 set mm=0%mm% if %hh% LEQ 9 set hh=0%hh% if %mn% LEQ 9 set mn=0%mn%
rename Customer01 "c:\test folder\temp\%yyyy%%mm%%dd%%hh%%mn%Customer01.txt"
End----
---------------- Here is what is in TimeStamp.vbs:
dd=day(date) mm=month(date) yyyy=year(date) hh=hour(time) mn=minute(time) wscript.echo dd&" "&mm&" "&yyyy&" "&hh&" "&mn ------------------
How would I wrap this and set it so that it will take care of Customer01 --- CustomerXX?
Thanks!This may work but I can't stress enough how you have to try to understand why.
Code: [Select]@echo off
for /f "tokens=1-5 delims= " %%A in ( ' cscript //nologo TimeStamp.vbs ' ) do ( set dd=%%A set mm=%%B set yyyy=%%C set hh=%%D set mn=%%E )
if %dd% LEQ 9 set dd=0%dd% if %mm% LEQ 9 set mm=0%mm% if %hh% LEQ 9 set hh=0%hh% if %mn% LEQ 9 set mn=0%mn%
for %%A in (\folder1\*.txt) do ( move %%A \new_folder\%yyyy%%mm%%dd%%hh%%mn%%%~nxA )
It relies on the code you posted earlier including the vbscript. Perhaps it can be replaced, but I didn't try. What I changed is rename -> move as you cannot change directories with a rename command.
I also added %~nxA to the end of the new filename. If you look at the help of the FOR command (FOR /?) you'll see that it replaces that with just the name of the file (no path info)
Hope this helps.uSlackr,
Thanks! This is working the way I need it to. I only have on little snag remaining....
in the live environment, the path contains a folder with a blank space (Program Files). I've tried using double quotes, but it doesn't seem to like them. Probably poor syntax on my part
Here is what worked in my test environment:
@echo off
for /f "tokens=1-5 delims= " %%A in ( ' cscript //nologo TimeStamp.vbs ' ) do ( set dd=%%A set mm=%%B set yyyy=%%C set hh=%%D set mn=%%E )
if %dd% LEQ 9 set dd=0%dd% if %mm% LEQ 9 set mm=0%mm% if %hh% LEQ 9 set hh=0%hh% if %mn% LEQ 9 set mn=0%mn%
for %%A in (c:\TestFolder\temp\*.txt) do ( move %%A c:\TestFolder\temp2\%yyyy%%mm%%dd%_%hh%%mn%_%%~nxA )
I need to replace TestFolder with Program Files.
Thanks!USlacker,
Hey... I finally got the quotes set up and t's working!
Thank you so much for your help!
|