I'm a newb when it comes to batch files so I apologize in advance...
I have over 800 folders which contain a number of files including a .txt file. I'm trying to move the .txt file from each of the folders into a single folder called "_Text Versions" (it already exists).
C:\
--->Users
------>David
--------->"Calibre Library"
------------>"Book Summaries"
--------------->(the folder name which is book title)
------------------>*.txt
But when I run my batch file I get no results ;-(
(Here's the .bat file contents)
@echo off
move C:\Users\David\"Calibre Library"\"Book Summaries"\*\*.txt C:\Users\David\"Calibre Library"\"Book Summaries"\"_Text Versions"
Thx in advance,
D
Batch Move Problem
Moderator: DosItHelp
Re: Batch Move Problem
Two things upfront
- It's sufficient and best praxis to enclose the entire path into quotes.
- Wildcards (like asterisk) are allowed in the last element of the path only. C:\foo\*\*.txt won't work. Not even C:\foo\*\bar.txt.
untested:
Note: All text files will be moved into the "_Text Versions" folder. No subfolders are created.
Steffen
- It's sufficient and best praxis to enclose the entire path into quotes.
- Wildcards (like asterisk) are allowed in the last element of the path only. C:\foo\*\*.txt won't work. Not even C:\foo\*\bar.txt.
untested:
Code: Select all
for /d %%i in ("%userprofile%\Calibre Library\Book Summaries\*") do (
move /y "%%~i\*.txt" "%userprofile%\Calibre Library\Book Summaries\_Text Versions\"
)
Steffen
Re: Batch Move Problem
That code won't quite work - the "_Text Versions" folder needs to be excluded as a source. And you can use ~dp to shorten the code a bit.
or maybe even simpler if you set current directory to the root
But either way, there will be problems if the same file name appears in multiple locations.
The following will prefix each name with the parent folder name so it is extremely likely there are no collisions
Dave Benham
Code: Select all
for /d %%D in ("%userprofile%\Calibre Library\Book Summaries\*") do (
if "%%~nxD" neq "_Text Versions" move /y "%%~D\*.txt" "%~dpD_Text Versions"
)
Code: Select all
pushd "%userprofile%\Calibre Library\Book Summaries"
for /d %%D in (*) do if "%%D" neq "_Text Versions" move /y "%%D\*.txt" "_Text Versions"
popd
The following will prefix each name with the parent folder name so it is extremely likely there are no collisions
Code: Select all
pushd "%userprofile%\Calibre Library\Book Summaries"
for /d %%D in (*) do if "%%D" neq "_Text Versions" for %%F in ("%%D\*.txt") move /y "%%F" "_Text Versions\%%~nxD__%%~nxF"
popd
Dave Benham