Moving Empty Folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

Moving Empty Folders

#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

Re: Moving Empty Folders

#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

Re: Moving Empty Folders

#3 Post by drgt » 16 Oct 2021 06:23

Thank you Steffen!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Moving Empty Folders

#4 Post by Squashman » 16 Oct 2021 14:14

You were shown how to read a file in several of your previous batch files.
viewtopic.php?f=3&t=7045&p=45954#p45954

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

Moving Empty Folders

#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

Re: Moving Empty Folders

#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

Moving Empty Folders

#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

Re: Moving Empty Folders

#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

Moving Empty Folders

#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?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Moving Empty Folders

#10 Post by ShadowThief » 18 Oct 2021 05:46

Exactly

Post Reply