Question

I'm putting together a batch file that can be dropped into a folder(named for each vendor) and create a folder structure based on the files inside and then move files into these folders. The files are saved as pdfs or dwgs. Currently the script reads for pdfs only. File examples: 001.pdf 002-r1.pdf

The script reads the second file and creates the folder structure as 002\REV 1 and then places the pdf in the last folder.

However when used for 001.pdf the folder structure is 001\REV How would I go about replacing the empty variable with a "0" or how would I change all the files in the folder into the same format XXX-rX.pdf

Thanks

@echo off
setlocal enabledelayedexpansion


for /f "tokens=1,2* delims=-r,." %%a in ('dir /b *.pdf') do 
(


md %%a\"REV %%b" 2>nul
move "%%a*.pdf" "%%a\REV %%b"
)
Was it helpful?

Solution

Going by the information you have provided, test this:

ren ???.pdf ???-r1.pdf

OTHER TIPS

Nevermind I got it. And added a timestamp and data logging text file.

@echo off
::create date variable
SET DayOfWeek=%Date:~0,3%
SET Day=%Date:~7,2%
SET Month=%Date:~4,2%
SET Year=%Date:~10,4%
SET Today=%Date:~4,2%/%Date:~7,2%/%Date:~10,4%

setlocal enabledelayedexpansion
::rename pdfs without revisions
ren ???.pdf ???-r0.pdf

::for loop to create folder and move pdfs
for /f "tokens=1,2* delims=-r,." %%a in ('dir /b *.pdf') do (

md "%%a\REV %%b" 2>nul

move "%%a-r%%b.pdf" "%%a\REV %%b"




::write to file 
echo %%a,%%b,%TODAY%>>data.txt
)   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top