Computer Hope
Microsoft => Microsoft DOS => Topic started by: jaburmester on February 23, 2017, 05:56:43 AM
-
@echo off
setlocal disableDelayedExpansion
cd C:\Documents and Settings\e51084\Desktop\New\Interest\f2
Set "SrcDir=C:\Documents and Settings\e51084\Desktop\New\Interest\f2"
Set "Mask=*.txt"
Set "Line#=23"
Set "LOfs=44"
Set "Len=46"
If /I Not "%CD%"=="%SrcDir%" Pushd "%SrcDir%"2>Nul&&(Set _=T)||Exit/B
For /F "Tokens=1-2* Delims=:" %%A In ('FindStr/N "^" "%Mask%" 2^>Nul'
) Do If "%%B"=="%Line#%" If Not "%%~C"=="" (Set "Line=%%C"
SetLocal EnableDelayedExpansion
If Not "!Line:~%LOfs%,%Len%!"=="" (
If Not Exist "!Line:~%LOfs%,%Len%!" (
Pause
Ren "%%A" "!Line:~%LOfs%,%Len%!"))
Pause
EndLocal)
If "_"=="T" PopD
The above searches a directory and renames fle name of all text files with some of the text within file.
I now need some help in how to remove / from !Line:~%LOfs%,%Len%! as filenames cannot have /.
If anyone can lead me in the right direction I would appreciate it.
All help appreciated
Thank you.
-
How about you use BB CODE tags to format your code. Indentation of your code also makes it easier to read. Especially when you line up the closing parentheses with the command it is finishing.
@echo off
setlocal disableDelayedExpansion
cd C:\Documents and Settings\e51084\Desktop\New\Interest\f2
Set "SrcDir=C:\Documents and Settings\e51084\Desktop\New\Interest\f2"
Set "Mask=*.txt"
Set "Line#=23"
Set "LOfs=44"
Set "Len=46"
If /I Not "%CD%"=="%SrcDir%" Pushd "%SrcDir%"2>Nul&&(Set _=T)||Exit/B
For /F "Tokens=1-2* Delims=:" %%A In ('FindStr/N "^" "%Mask%" 2^>Nul') Do (
If "%%B"=="%Line#%" If Not "%%~C"=="" (
Set "Line=%%C"
SetLocal EnableDelayedExpansion
If Not "!Line:~%LOfs%,%Len%!"=="" (
If Not Exist "!Line:~%LOfs%,%Len%!" (
Pause
Ren "%%A" "!Line:~%LOfs%,%Len%!"
)
)
Pause
EndLocal
)
)
If "_"=="T" PopD
How about you also show us examples of the input files you are parsing.
-
If you see scrip previously shown it take files like attachment and renames them in this case NICOS A. KYRATZIS AND/OR - 222222.txt but you cannot have / in filename so I need a way to replace / with space.
Hope this helps.
Thank you for all help.
[attachment deleted by admin to conserve space]
-
You just need to add one line of code to replace the / with a space.
SET "Line=!Line:/= !"