Solved Please help with script Change the folder naming conventon

October 29, 2012 at 01:14:08
Specs: Windows 7
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1-2* delims=_" %%a in ('dir /b *.au') do (
set d=%%c
set d1=!d:~1,4!\!d:~5,2!\!d:~7,2!
md !d1!
move %%a_%%b_%%c !d1!\
)

This script creates folders and sub-folders according to te name of the file.

Currently it creates sub-folder 01,02,03 ect. I need the 0 to be removed so that the sub-folders are named 1,2,3,4 ect

Thank you so much in advance


See More: Please help with script Change the folder naming conventon

Report •


✔ Best Answer
October 30, 2012 at 12:25:54
set d=%c

should be:
set d=%%c

(any "loop" variable, within a batch file, should have two percents in front and none after. commandline batch statements they only have one percent.)

And, you got this reversed:
set d1=!d1:\=0\!

it should be:
set d1=!d1:\0=\!

(This is a string-conversion operation, and the string in front of the equals is the "from" string, the item after the equal is the "to", so having it backwards would generate stuff like 20120\100\30)
Aside from that, everything should work.



#1
October 29, 2012 at 01:18:14
Post a few file names.


====================================
Life is too important to be taken seriously.

M2


Report •

#2
October 29, 2012 at 11:11:55
@M2, the files look like the ones in this (original) post::
http://www.computing.net/answers/pr...

after this line:
set d1=!d:~1,4!\!d:~5,2!\!d:~7,2!

add this line:
set d1=!d1:\0=\!


Report •

#3
October 30, 2012 at 06:25:44
Thank you so much but I still cannot get it right if I add the line to the script it does nothing

@echo off & setlocal enabledelayedexpansion
for /f "tokens=1-2* delims=_" %%a in ('dir /b *.au') do (
set d=%c
set d1=!d:~1,4!\!d:~5,2!\!d:~7,2!
set d1=!d1:\0=\!
md !d1!
move %%a_%%b_%%c !d1!\
)


Report •

Related Solutions

#4
October 30, 2012 at 06:27:19
This is what it looks like. Am I Doing something wrong?

Report •

#5
October 30, 2012 at 06:50:03
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1-2* delims=_" %%a in ('dir /b *.au') do (
set d=%c
set d1=!d:~1,4!\!d:~5,2!\!d:~7,2!
set d1=!d1:\=0\!

md !d1!
move %%a_%%b_%%c !d1!\
)


is this the right way to do it?


Report •

#6
October 30, 2012 at 12:25:54
✔ Best Answer
set d=%c

should be:
set d=%%c

(any "loop" variable, within a batch file, should have two percents in front and none after. commandline batch statements they only have one percent.)

And, you got this reversed:
set d1=!d1:\=0\!

it should be:
set d1=!d1:\0=\!

(This is a string-conversion operation, and the string in front of the equals is the "from" string, the item after the equal is the "to", so having it backwards would generate stuff like 20120\100\30)
Aside from that, everything should work.


Report •

#7
October 30, 2012 at 22:50:24
This worked perfectly thank you so much. I have another question. this is what my script looks like in its whole.

@echo off
echo Copying latest version ...
XCOPY "\\192.168.3.2\calloseum\JavaUpdates" "C:\Java Leads System" /d /Y

@echo off & setlocal enabledelayedexpansion
for /f "tokens=1-2* delims=_" %%a in ('dir /b *.au') do (
set d=%%c
set d1=!d:~1,4!\!d:~5,2!\!d:~7,2!
set d1=!d1:\0=\!

md !d1!
move %%a_%%b_%%c !d1!\
)


echo Starting application ...
c:
cd \Java Leads System
javaw -jar TELETECH.JAR

@echo off
echo Copying from local to server
XCOPY "C:\Java Leads System\2012" "\\192.168.3.4\javaleadssystem\Recordings for cant find audio files\2012" /D /E /C /F /Y


exit

What I need now is to be able to delete the files and folders older than X amount of days.

This is what the script looks like and it works but I need it to only delete files or folders older than X in the 2012 folder and also I get an error. If the forfiles.exe is in the folder.

Set _tmpfl=%temp%\~rdfldr
Set _Source=C:\Javaleadsystem
If Exist "%_tmpfl%.*" Del "%_tmpfl%.*"
Forfiles /p "%_Source%" /S /D -1 /C "Cmd /C If @isdir==TRUE Echo @RD @Path 2^>Nul" >"%_tmpfl%.bat"
Forfiles /P "%_Source%" /S /D -1 /C "Cmd /C If @isdir==FALSE Del @Path"
Sort /R "%_tmpfl%.bat" /O "%_tmpfl%.cmd"
"%_tmpfl%.cmd"
If Exist "%_tmpfl%.*" Del "%_tmpfl%.*"

Thank you so much


Report •


Ask Question