Jump to content

How do I set a batch file .txt output save location

Kilage
Go to solution Solved by Helibert,
@echo off
dir /b /s Movies\*.* > list1.txt

for /f "tokens=*" %%A in (list1.txt) do echo %%~nxA >> movieslist.txt

del list1.txt

instead of changing the path just use the path in the dir command itself. 

First line creates a temporary list.txt with all files with full path recursively in the specified path .

Second line does a for loop over every entry an only prints the filename instead of the full path

third line deletes the temporary file

I made a super basic batch file to save all the file names of my movies in my movie folder to a txt. I have everything working except

1) I don't know how to have the movielist.txt save to the .bat file location instead of the movies folder

2) I just realised it's recording the name of the subfolders instead of the files in them

I've tried googling the answer but I think I'm not wording my searches correctly because the only results I can find are how to make the batch file output a txt, not change the save location. Here's the code that I have:

@echo off

cd Movies
dir /b > movieslist.txt

I would like to have the batch file output the file names in the folder (Movies) and subfolders and save the output txt to the folder the batch file is currently in. I am very much so a novice when it comes to batch files, the extent of my experience being launching minecraft with more RAM. Thank-you in advance for the help!

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

@echo off
dir /b /s Movies\*.* > list1.txt

for /f "tokens=*" %%A in (list1.txt) do echo %%~nxA >> movieslist.txt

del list1.txt

instead of changing the path just use the path in the dir command itself. 

First line creates a temporary list.txt with all files with full path recursively in the specified path .

Second line does a for loop over every entry an only prints the filename instead of the full path

third line deletes the temporary file

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×