problems with spaces for variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
songkok
Posts: 3
Joined: 03 Feb 2009 14:04
Location: Germany

problems with spaces for variable

#1 Post by songkok » 04 Feb 2009 22:36

Hello all DOS fan! :D

i am sorry if this same problems had been asked before, but i could not find the answer.

i want to list the attributed file with

Code: Select all

attrib /s >> file.txt


and this files need to be first renamed and then copied to another backup folder. for this i use the FOR command.

apparently some of the folder and file names have spaces and i only knew that FOR can only takes up to 3 variable.

for example if one of the list is

Code: Select all

A      D:\Computer\DOS\problems with\spaces for \vari able\2090811.txt

and the variables for the FOR command can only read up until "with\spaces".

are there any solution to this.? :?: :roll:

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 05 Feb 2009 09:25

This should get you started. It's similar to my issue in another thread:

Code: Select all

 SETLOCAL ENABLEEXTENSIONS
 SETLOCAL ENABLEDELAYEDEXPANSION

 Attrib /s > Attrib.List
 
 For /F "Delims=" %%F In (Attrib.List) DO (

     Set "f=%%~nxF"
     Set "p=%%~pF"

     CD /D "!p!"
     Copy !f! "\BackupFolder\<NewName Goes Here>"     

 )


Remember that the ">" creates a new file and ">>" appends to an existing file. Based on your example, if you're calling this script multiple times it will keep adding to the file every time you run the "Attrib /s >> File.txt" command.

HTH
-R

Post Reply