Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am running batch files from WinXP SP1, and when I export a list of folders to a text file, they are exported with long folder and file names that CANNOT be read back into my FOR loop.
e.g. Batch file produces a text document containing lines like this:
c:\Test\Somechappy\Application Data
c:\Test\Somedude\Application Data
c:\Test\Somebloke\Folder\Application Data
c:\Test\Someguy\Temp Folder\Application Databut attempting to use the text file in a FOR loop results in a "File not found" error because none of my batch files can handle files/folders of more than 8 characters.
To make the batch file work you have to replace a lot of the text.
c:\Test\Somech~1\Applic~1
c:\Test\Somedude\Applic~1
c:\Test\Somebl~1\Folder\Applic~1
c:\Test\Someguy\TempFo~1\Applic~1Can I get my batch files to recognise long folders and filenames? Otherwise I need to change the line that creates the text file somehow :
DIR /S /B /AD c:\Test\\Applic~1*.* > LIST.txt
or do some horrendous "replace text within file" command using wildcards that I don't even know are supported.
Um....help
Dan The Man

Can you post the BAT?
Not obvious what's "not working".
M2
If at first you don't succeed, you're about average.

Another thing comes to mind. If you are doing something that applies to all registered users on a computer, why not use All User user name. Thats what it is there for.
You may also find thats its not the LFNs that are causing you problems, but spaces within the file name. One way round that is to enclose the entire path name inside double quotes.
Stuart

This line exports the paths of all "Application Data" folders to a text file called List.txt
REM DIR /AD /S /B c:\Test\Applic~1*.* > List.txt
I had to change "Application Data" to "Applic~1" before it would work. The text file ends up looking like this:
c:\Test\Somechappy\Application Data
c:\Test\Somedude\Application Data
c:\Test\Somebloke\Folder\Application Data
c:\Test\Someguy\Temp Folder\Application DataBack in the batch file, this line then reads from that text file and deletes the contents of each folder.
FOR /F %%a IN (List.txt) DO DELTREE /Y %%a\*.*
But it doesn't work because the directories are exported with long filenames. The only way I have got it to work is to replace lines in the text file:
c:\Test\Somechappy\Application Data
replaced by:
c:\Test\Somech~1\Applic~1then it works, so it is definitely to do with the path, you can display short paths with DIR with the /B switch but it doesn't write short paths to the text file.
The allusers approach is a good idea but won't work for me because a)I'm deleting files not supplying them b)I'm going to use this batch file on a network location.
Thanks though.Any thoughts?
Dan The Man

"Subject: Long filenames not supported proble"
Ah! What exquisite irony!
Actually I'm fairly sure I just missed the m
Dan The Man

Hi Dan,
Try this:
::==
dir /ad /b /s "some long" > list.txt
for /f "tokens=*" %%L in (list.txt) do deltree /y "%%L"
::==M2
If at first you don't succeed, you're about average.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |