Page 1 of 1

problems with spaces for variable

Posted: 04 Feb 2009 22:36
by songkok
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:

Posted: 05 Feb 2009 09:25
by RElliott63
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