-
October 13th, 2004, 04:26 AM
#1
Renaming files using a batch script
I receive a file from an external source on my PC each day with the name format:
FILE-01_CSV.yyyymmdd.output.csv
I have a batch script which moves this file to a shared directory. However, my users can't automatically import the file into their database because of the dots in the filename. Is there a simple way to rename the file, keeping the .csv extension but replacing all the other dots in the filename with an underscore? My script runs on NT. Thanks in advance.
-
October 18th, 2004, 04:28 AM
#2
Hi Dave, Sorry for the delay in replying.
Your batch file uses simple DOS commands.
Use the COPY command to copy it from source directory to destinantion directory with new filename.
e.g.
Code:
COPY FILE-01_CSV.yyyymmdd.output.csv d:\sharedir\FILE-01_CSV_yyyymmdd_output.csv
-
October 18th, 2004, 04:46 AM
#3
Hi Smurfy,
That would be fine if I was working with a fixed filename but the filename changes each day (the yyyymmdd being the date). I think that I really need some sort of filename manipulation routine which parses the name of the file coming in to build up the name of the output file.
-
October 18th, 2004, 08:26 PM
#4
Is it possible to get the people who generate the file to name it FILE-01_CSV_yyyymmdd_output.csv ?
Then you don't need to rename it.
-
October 18th, 2004, 10:14 PM
#5
Or try this
Code:
Set CURRDATE=%TEMP%\CURRDATE.TMP
DATE /T > %CURRDATE%
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
copy FILE-01_CSV.yyyymmdd.output.csv x:\share\FILE-01_CSV_%yyyymmdd%_output.csv
Which basically works out what the date is in YYYYMMDD format and then copies the file renaming and inserting the date.
With thanks to http://discussions.virtualdr.com/sho...hreadid=157827
and thus http://www.winnetmag.com/Article/Art...575/13575.html
Last edited by Nix; October 18th, 2004 at 10:24 PM.
-
October 19th, 2004, 04:30 AM
#6
Hi Nix,
That's almost what I need. The only problem that remains to be solved is that the file arrives just after midnight and has the previous day's date. How do I subtract 1 from the current machine date?
-
October 19th, 2004, 08:31 PM
#7
I have sent a PM to Vernon Frazee who is our resident expert of DOS batch files.
Hopefully he can assist.
-
October 20th, 2004, 09:02 AM
#8
Don't have a NT machine handy to try the following BATch file on but it looks like it'll do what you're after on XP:
Code:
@echo off
if exist FILE-01_CSV.*.csv goto Begin
echo.
echo Error: No "FILE-01_CSV.*.csv" files exist in the current directory
goto End
:Begin
echo The following file(s):
dir/b FILE-01_CSV.*.csv
echo.
echo has/(have) been renamed to:
dir/b FILE-01_CSV.*.csv>$temp$.tmp
for /f "eol=; tokens=1,2,3,4 delims=." %%i in ($temp$.tmp) do ren %%i.%%j.%%k.%%l %%i_%%j_%%k.%%l
del $temp$.tmp
dir/b FILE-01_CSV_*.csv
:End
Note that you'll need to be in the directory (folder) along with your "FILE-01_CSV.yyyymmdd.output.csv" files before running the above.
-
August 6th, 2017, 10:05 AM
#9
 Originally Posted by DaveVod
I receive a file from an external source on my PC each day with the name format:
FILE-01_CSV.yyyymmdd.output.csv
I have a batch script which moves this file to a shared directory. However, my users can't automatically import the file into their database because of the dots in the filename. Is there a simple way to rename the file, keeping the .csv extension but replacing all the other dots in the filename with an underscore? My script runs on NT. Thanks in advance.

Hello,
There is a simple solution for your trouble. I suggest you to try BatchRenameFiles Tool program and you can change pretty much everything you want.
-
August 6th, 2017, 01:17 PM
#10
Please be aware this thread is 13 years old. And as such will now be closed.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|