Ready, steady… save!
You don’t need a chart to join in. Here are 2 ways to record your savings:
1. Cross it off
Pop a chart into your first post. Saved an amount? Cross it out! Read more »
£0.01 £0.02 £0.03
2. Write it down
Skip the chart and add updates to your first post. Read more »
“Another +£3 saved today. Go me!”
Use +£ before each new saving so it counts towards your total.
We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
Generate a list of Path Statements for lots of scattered files
Comments
-
psychic_teabag wrote: »I'm confused... as far as I can tell, you already have a file containing the filenames you want to process, yet most of the responses seem to be using dir to generate a new list.
What do you mean by a "path statement" ? My understanding was that the file you have is already a list of paths of the files you want.
I think that the OP has a list of file names i.e. xyz.jpg, and s/he wants to turn them into a list of full pathnames, i.e.
\folder\subfolder\xyz.jpg. The issue being that the files are spread across a number of folders. 0 -
psychic_teabag wrote: »I'm confused... as far as I can tell, you already have a file containing the filenames you want to process, yet most of the responses seem to be using dir to generate a new list.
What do you mean by a "path statement" ? My understanding was that the file you have is already a list of paths of the files you want.
Hi
yes, I have a list of the filenames that I want to operate on.
If file P0589375.jpg happens to be in folder Folder1\Subfolder3, I want to generate an entry in a textfile which gives the path statement C:\Folder1\Subfolder3\P0589375.jpg without my having to manually search through the subfolders to find it. Plus the same for its friends in my original list, but not for anything that is not in my list.
I think that the suggestions about using dir are to generate a list of all the files in C:\Folder1\Subfolders 1 to 6, that can be used to refer against in a VLOOKUP command in Excel.
I haven't tried doing it yet, I will have a go at it at the weekend...0 -
Ah, okay, so you have a text file containing things like
abc.jpg
def.jpg
and while you know that those files exist somewhere, you don't know exactly where.
Okay, I vaguely recall that you can use dir /b to get a "bare" listing of a file. So dir/b/s abc.jpg would do a recursive search for files called abc.jpg and print the path.
https://ss64.com/nt/dir.html
So you just need to combine that with the for loop to iterate that for all the leaf names in the text file.
(Sorry, I don't have access to a windows machine to try it out.)0 -
Suppose you have all the filenames in a file called d:\filenames.txt and that all the jpg files are on the E:\ drive then you can make use of psychic teabag's suggestion by running a BATch file called, say, d:\pather.bat:
cd e:\
for /f %%a in (d:\filenames.txt) do (
dir /b /s %%a >> d:\files-with-paths.txt
)
notepad d:\files-with-paths.txt
Change the various paths to suit your situation - or ask if unsure!
0 -
I've not come across the FOR command before in BAT files, so I had a play, and the following will do what the OP wants:-
FOR /f "delims=" %%G in (filelist.txt) DO DIR /b /s %%G >>fpaths.txt
Where filelist.txt holds the filenames, one per line, and fpaths.txt is empty or non-existent before running the command.
You can add a CD command before the above to restrict the extent of the search for the files.0 -
Not bad if you've never used the FOR statement before!0
-
-
Possibly slightly better to put a single > for the loop, rather than >> inside the loop. Something like
( for ... do dir ... ) > output.txt
You'd presumably only need to double up the %% if you are putting this into a bat file to execute it. If you just do it at the prompt, it would be single %
Possibly more efficient would be if you could do
dir/s/b abc.jpg def.jpg ...
but I can't immediately think how you collect all the lines of a file onto a single line under windows. (Possibly use a for loop and keep appending to a variable.) Doing it that way, the dir would only have to recurse once, rather than having to do a new search for each filename.0 -
The only difference between using > and >> for redirection is that the former will always start with an empty file.
*.jpg would be even better than abc.jpg def.jpg, etc, if all the JPEGs were required. There are several ways to get the required result, and it's not worth spending huge amounts of time if it's just a one-off...
If I was writing that BATch file as I would normally do, it would probably be five times the length and be riddled with comments!0 -
just a note - some of the file extensions are uppercase and some are lowercase. I would like to preserve the case. Does that make a difference ? - thanks0
This discussion has been closed.
Categories
- All Categories
- 356K Banking & Borrowing
- 255K Reduce Debt & Boost Income
- 456.3K Spending & Discounts
- 248.5K Work, Benefits & Business
- 606.4K Mortgages, Homes & Bills
- 179.1K Life & Family
- 264.1K Travel & Transport
- 1.6M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.7K Read-Only Boards

