Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#1
Post
by drgt » 16 Oct 2021 05:54
I want to move empty folders specified in List.txt using the FOR command.
What am I doing wrong?
Screen Dump
C:\Documents and Settings\user\Desktop\New Folder (5)>for %x in ("C:\Docume
nts and Settings\user\Desktop\New Folder (5)\List.txt") DO move %x "C:\Docum
ents and Settings\user\Desktop\New Folder (4)\empty"
This moved the List.txt to the destination instead of the entries in List.txt
Contents of List.txt
"C:\Documents and Settings\user\Desktop\New Folder (5)\1"
"C:\Documents and Settings\user\Desktop\New Folder (5)\2"
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 16 Oct 2021 06:04
If you want to read the file you have to use a FOR /F loop like
Code: Select all
for /f "usebackq delims=" %%x in ("C:\wherever\file.txt") do ...
Steffen
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#3
Post
by drgt » 16 Oct 2021 06:23
Thank you Steffen!
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#5
Post
by drgt » 16 Oct 2021 22:52
Thank you for pointing that out!
Alzheimer is setting in!
Although I do not really understand the difference between "delims=" and "usebackq delims="...
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#6
Post
by aGerman » 17 Oct 2021 04:06
Without USEBACKQ, a string enclosed in double quotes is treated as string stream of characters. Since file names/paths can and often do contain spaces and other special characters requiring quotes, you have to change the semantics of the supported quotation marks (", ', and`). With USEBACKQ, a string enclosed in double quotes is treated as file path and is opened as file stream for reading.
Steffen
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#7
Post
by drgt » 17 Oct 2021 08:58
Like I said,... Alzheimer & brain damage!
Perhaps examples to use one or the other will help.
Are there instances where one will work but not the other (and vice versa)?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#8
Post
by aGerman » 17 Oct 2021 09:08
Since it is best practice to always quote paths (regardless whether they actually contain spaces or special characters like ampersands), you have to use them along with USEBACKQ in a FOR /F loop.
Read the help message of FOR in order to understand how the semantics of quotes are changed by USEBACKQ. I'm not willing to copy/paste those things into forum posts.
Steffen
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#9
Post
by drgt » 17 Oct 2021 09:14
OK.
By help message I suppose you mean the one shown when I type for /? I on the command prompt?