How do I copy a single PDF file and batch paste it into hundreds of files with a specific naming convention based on a source .csv or Excel file? - batch-file

I'm trying to copy a single PDF document into several hundred PDF documents, but they have to have a specific naming convention based on specific user data stored in a .csv (or text, or Excel, any of these sources is fine). I imagine I could use PowerShell for this, but don't know how to approach.
Example:
Take a single PDF - sample.pdf - and rename into 00003021_20160204.pdf where the '00003021_20160204' is one specific user record in the source .csv. I would then copy sample.pdf and repeat the above process several hundred times until my source list was complete.
Note, these are sequential numbers, so I have to rely on the source data.
I tried search stack and google, but found nothing. Though I'm open to suggestions on how I (or others) might better search for this solution in the future.
Thanks!

for /F %%p in (files.txt) do copy %1 "%%p.pdf"
where files.txt has a number on each line and the first parameter is the pdf you want to copy.

Related

Update file across multiple folder locations?

I need something that can copy a specified file any and everywhere on my drive (or computer) where that file already exists; i.e. update a file. I tried to search this site, in case I'm not the first, and found this:
CMD command line: copy file to multiple locations at the same time
But not quite the same.
Example:
Say I have a file called CurrentList.txt, and I have copies of it all over my hard drive.  But then I change it and I want all the copies to update.  So I want to copy the newer one over all the others.  It could 'copy if newer', but generally I know it's newer, so it could also just find every instance and copy over it.
I was originally going to use some kind of .bat file that would have to iterate over every folder seeking the file in question, but my batch file programming is limited/rusty.  Then I looked to see if xcopy could do it, but I don't think so...
For how I will use it most, I generally know where those files are going to be, so it actually might be as good or better if I could specify it to (using example), "copy CurrentList.txt, overwriting all other copies wherever found in the C:\Lists folder and all subfolders".
I would really like to be able to have it in a context menu, so I could (from a file explorer) right click on a file or selected files and choose the option to distribute it.
Thanks in advance for any ideas.
Use the "replace" command...
replace CurrentList.txt C:\Lists /s

How would I store different types of data in one file

I need to store data in a file in this format
word, audio, jpeg
How would I store that all in one file? Is it even possible do would I need to store links to other data files in place of the audio and jpeg. Would I need a custom file format?
1. Your own filetype
As mentioned by #Ken White you would need to be creating your own custom file format for this sort of thing, which would then mean creating your own parser type. This could be achieved in almost any language you wanted but since you are planning on using word format, then maybe C# would be best for you. However, this technique could be quite complicated and take a relatively large amount of time to thoroughly test your file compresser / decompressor, but may be best depending on your needs.
2. Command line utilities
Another way to go about this would be to use a bash script to combine all of the files into one file, and then decompress it at the other end. For example the steps could involve:
Combine files using windows copy / linux cat command on command line
Create a metdata file of your own that says how many files are in this custom file, and how much memory each one takes up (could be a short XML or JSON file for example...)
Use the linux split command or install a Windows command line file splitter program (here's just one example) to split the file back into whatever components have made it up.
This way you only have to create a really small file type, and let the OS utilities handle the combining of them for you.
Example on Windows:
Copy all of the files in your current directory into one output file called 'file.custom'
copy /b * file.custom
Generate custom file format describing metadata (i.e. get the file size on disk in C# example here). This is just maybe what I would do in JSON. SO formatting was being annoying so here's a link (Copy paste it into an editor or online JSON viewer).
Use a decompress windows / linux command line tool to decompress each files to the exact length (and export it back to the exact name) specified in the JSON (metadata) file. (More info on splitting files on this post).
3. ZIP files
You could always store all of the files in a compressed zip file, and then just use a zip compressor, expander as and when you like to retreive any number of file formats stored within.
I found a couple of examples of :
Combining multiple files into one ZIP file in only C# .net,
Unzipping ZIP files in C#
Zipping & Unzipping with only windows built-in utilities
Zipping & Unzipping in Linux command line
Good Zipping/Unzipping library in Java
Zipping/Unzipping in Python

Using a batch file to copy multiple files with the same name, and past into new folder with differing names

I have a long list of files that are auto-produced every month. they'll all have the same file name, with a sequential file extension like this:file.001, file.002, file.003
Each file has differing information, despite having the same name. What I need to do is copy them from their home directory and paste them into a new directory with names that reflect their purpose, and as text files, like this: Budget.txt, Expense.txt, Retention.txt
Is it possible to do this with a batch file? I've been unable to find a method that works. Any help would be appreciated.
EDIT: I've tried that solution, and it works as far as it goes. the frustrating thing is that the extensions are not always the same, but always sequentially numbered.

batch file copy multiple .txt files with date restrictions from multiple directories to one directory

I am trying to copy all .txt files that I have scattered throughout several subdirectories of one main directory into another directory using a batch file. I have research this site and found lots of answers at this link: batch file Copy files with certain extensions from multiple directories into one directory. Like the code below from Jay:
set dSource=C:\Main directory\sub directory
set dTarget=D:\Documents
set fType=*.doc
for /f "delims=" %%f in ('dir /a-d /b /s "%dSource%\%fType%"') do (
copy /V "%%f" "%dTarget%\" 2>nul
)
My question is how to modify this code or other codes on this link to batch copy the files with time stamps, like I only want to copy .txt files created from Jan 1, 2012 to Nov 1, 2012.
My suggestion for finding and moving *.txt files in a directory tree of a drive, or the entire drive, or even multiple drives with last modification date in a definite time period is:
Start Windows Explorer.
Click on button Search.
Open advanced search options for finding files and folders.
Select/enter to search for files by last modification date.
Enter the two dates to specify time period or select the time period.
Run the search.
Select all found files in search result, for example with Ctrl+A.
Press Ctrl+X to mark the found files for being cut (moved).
Open the folder into which the files should be moved.
Press Ctrl+V to paste the files (move them).
That's it.
Nobody needs to code a batch job for this task if this find + move files job should not be done periodically using a scheduling task.
The exact steps for doing such an advanced find for files in a definite time period with Windows Explorer depends on version of Windows. See for example the computer tips
Find files by date modified in Windows for Windows 8/7/Vista, or
for Windows XP: How do I search for a file on my computer?
And of course there are many freeware and shareware tools which support also finding files according to various search criterias like last modification date within a specified time period and move them.
Well, that does not really answer the question as it does not contain the batch code for doing the job. So I answer this question with another question:
Why thinking about coding a batch file for such a task hard to adapt for varying dates if dozens of GUI applications including Windows Explorer exist doing the same by simple user input with no need on coding skills and therefore very easy to use, and the find + move must be done only once or from time to time with changed criterias?

Creating a batch file to do drag and drop files onto an exe

I have an exe that I can drag and drop another file onto to produce a third file. Unfortunately it seems to accept only 1 file at a time, if I select multiple and drop it doesn't seem to work.
How do I create a batch file to automate the process of dragging a thousand files of .drag extension onto drop.exe?
Thanks!
In Windows, dropping a file on an exe just executes the command line:
fileprocessor.exe "<full path to dropped file>"
So you should be able to just call the exe directly in your batch file, passing the path to each file that you'd like to process.
EDIT: Look into the For batch command to do this for a series of files. You should be able to specify the wildcard and then call the command for each.
For %%a in (*.drag) do fileprocessor.exe "%%~fa"
Evidently, batch files can have multiple objects dropped onto them. See this question. You should be able to adapt the answer to your needs. I do wonder if there is a maximum number of characters that can be passed in, though, so you might not be able to drag thousands of files onto it. Possibly not even hundreds. But definitely multiple.
EDIT: In your comment to dmercredi's answer, you mention wildcards. If you don't need the drag/drop capability and just want to specify *.drag in your batch file, check out this question instead. There are a variety of answers there that may suit your needs.

Resources