Batch script to copy filenames?

May 26, 2011 at 10:22:42
Specs: Windows 7
Hi guys,

I'm trying to create a batch script that:

-Copies the new files' filenames
-Pastes each filename in a new line in a text file before the last line

For example:

I have files named Picture.JPG and Picture2.JPG in the folder
The batch needs to copy the filenames "Picture" and "Picture2" and pastes it in textfile.txt, which already has a last line that I don't want to overwrite, so it would appear like this:

Picture
Picture2
This is the last line

Note that I don't want the .JPG extension in the text file.

Any ideas?


See More: Batch script to copy filenames?

Report •


#1
May 27, 2011 at 00:59:30
How are new files to be defined? By last written date/time or some other method? In other words, if the folder contains many *.jpg files how are new files to be selected?


Please come back & tell us if your problem is resolved.


Report •

#2
May 27, 2011 at 10:19:17
I'm just going to stick the new files in a folder called "Processing" and at the end of the batch script I would just move the files to the right location. So identifying new files wouldn't be a problem because the script would just have to copy every filename in the Processing folder.

One thing to add, I want to paste the filenames in between TWO lines. So it shows up like this:

This is the first line
Picture
Picture2
This is the last line

Thanks guys!


Report •

#3
May 27, 2011 at 15:27:48
This works in XP, please test in Win 7. Input.txt contains the original two lines.

@echo off
setlocal 
cls

set /p firstline=<input.txt

for /f "tokens=*" %%1 in (input.txt) do (
    set lastline=%%1
)

echo %firstline%>outputfile.txt

for /f "delims=*" %%1 in ('dir /b /on processing\*.jpg') do (
    echo %%~n1>>outputfile.txt
)
    
echo %lastline%>>outputfile.txt

type outputfile.txt


Please come back & tell us if your problem is resolved.


Report •
Related Solutions


Ask Question