Saved Bookmarks
| 1. |
Solve : File Renaming help needed. (SOLVED)? |
|
Answer» I have a daily file from my system that comes like the following: You could do something like this:that won't really do what OP requested, although it can be done manuallyNo, that won't do. To make it simple this is what I want. Original file name "ttx_export_20070622.txt" I want a script to rename it to "01_20070622.txt" Tks Sometimes it is easier to do ONE file at a time. Code: [Select]@echo off for /f "tokens=1-3 delims=_"" %%i in ('dir *.txt /b /s') do ( ren %%i 01_%%k ) You really didn't give us enough info on your directory structure and your first request has no underscore in the renamed file but your last post does. I'll let you fix up the code as you see fit. Quote from: Sidewinder on June 22, 2007, 04:52:32 AM Sometimes it is easier to do one file at a time. Thanks for this help. Here is the directory info and my real file names. I would really appricate if you can help me on this: Directory = c:\bat\export Org File = ttx_export_20070622.txt Expected File = 0120070622.txtI just noticed my first reply was a little heavy on the keyboard. This might work for your situation: Code: [Select]@echo off for /f "tokens=1-3 delims=_" %%i in ('dir c:\bat\export\*.txt /b /s') do ( ren %%i 01%%k ) Good luck. I created a batch file CALLED do.bat with the following contents: Quote @echo off When I execute the do.bat file I am getting the following error: Quote The system can not find the file specifiedCode: [Select]@echo off for /f "tokens=1-3 delims=_" %%i in ('dir c:\bat\export\*.txt /b') do ( ren %%i_%%j_%%k 01%%k ) I need more sleep. Great, works file. Thanks a lot!This thread was useful for me to rename a set of rar files to remove a single space and REPLACE it with a more compliant underscore so that I could then do a batch unrar to individual folders that I wanted to specify numerically with a loop. Like this: Code: [Select]@setlocal @echo off echo renaming archives to remove spaces... for /F "tokens=1-3 delims=. " %%i in ('dir /b *.rar') do call :do_rename "%%i" "%%j" "%%k" echo extracting archives to separate directories... for /F "tokens=1,2 delims=." %%i in ('dir /b *.rar') do call :do_extract "%%i" "%%j" goto :eof :do_rename ren "%~1 %~2.%~3" "%~1_%~2.%~3" :do_extract echo extracting %~1.%~2 mkdir "%~1" unrar e -inul "%~1.%~2" "%~1" But what if I have filenames with an arbitrary number of spaces in the filename? Obviously I can't pass in an arbitrary number of parameters into the label call. Or can I? I would like to avoid parsing the data and storing count data in a temporary file. Ideally, it would best to do it all in a single loop traversal but is batch file processing that powerful? I am guessing it is but I don't know. Any help would be greatly appreciated. Have I made myself clear enough? Egads, Josh |
|