Command to create a file based on filename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
cappsie
Posts: 1
Joined: 11 May 2012 08:45

Command to create a file based on filename

#1 Post by cappsie » 11 May 2012 09:00

Hi,

I generate two PDF files, generally something like Z123456_1 and Z123456_2.

I then merge the files using PDFSAM: http://www.pdfsam.org

What I'd like to do change the "merge.pdf" to the Z123456.
Then I need to create a datestamped-directory, with the the Z123456 as the name.

Finally, I copy the three PDFs into that directory.

Clear as mud?

Thanks in advance :)

Adam

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Command to create a file based on filename

#2 Post by foxidrive » 11 May 2012 09:32

I can't understand your request.

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Command to create a file based on filename

#3 Post by Aacini » 11 May 2012 10:43

Code: Select all

@echo off
rem This Batch file take "Z123456..." name in the first parameter
rem Here: Generate the two PDF files
rem Here: Merge the files
for /F "delims=_" %%a in ("%~1") do set baseName=%%a
ren merge.pdf "%baseName%.pdf"
for /F "tokens=1-3 delims=/" %%a in ("%date%") do (
   rem Next line must be changed accordingly to locale date format:
   dateStamp=%%c%%a%%b
)
md "%dateStamp%_%baseName%"
copy "%baseName%*.pdf" "%dateStamp%_%baseName%"

Post Reply