Batch File Help Please ( reference a text file )
Moderator: DosItHelp
-
- Posts: 19
- Joined: 23 Jul 2013 12:45
Batch File Help Please ( reference a text file )
I would like to write a specific batch program on a flash drive that i will use repeatedly, but on different computers so the directorys will change. Therefor i would like to put a .txt file that i can paste the directory in so that when the batch file runs, it looks into that .txt file and uses whatever is in there as the directories to use. how is this accomplished? thank you very much.
Re: Batch File Help Please ( reference a text file )
The correct answer which works depends on your code.
People that read your question can make assumptions about how your code works
but it can be a frustrating experience when it's wrong, and then a to-and-fro starts
with 20 questions to find out exactly how the task is meant to work.
People that read your question can make assumptions about how your code works
but it can be a frustrating experience when it's wrong, and then a to-and-fro starts
with 20 questions to find out exactly how the task is meant to work.
-
- Posts: 19
- Joined: 23 Jul 2013 12:45
Re: Batch File Help Please ( reference a text file )
well it would be using different things. like xcopy or dir or rename or move ect.. i am just wondering if there is a way that whenever i enter a certain directory, instead of writing it in the batch file i can type a certain code that will reference a specified txt file, this way i can just paste in the directories i want to use in the specified txt files so i can just run the batch file, instead of having to adjust each batch file whenever the directory changes.. just wondering if there is a general command function for that.. thanks..
Re: Batch File Help Please ( reference a text file )
This will get the first line of a text file into a variable:
Code: Select all
@echo off
set /p directory=<"file.txt"
echo "%directory%"
pause
-
- Posts: 19
- Joined: 23 Jul 2013 12:45
Re: Batch File Help Please ( reference a text file )
Im not sure if that will work exactly, what i have is this
Xcopy C:\Example\123\0.jpg C:\Destination\123\0.jpg
but i have hundreds of lines at a time to do this, and the starting point and folder names are constantly changing. Not the jpg, just the folder that it is in. So i would like to have 2 .txt files, one i can paste a location in and the other a file name
example-
location.txt has "C:\System\here" in it
Files.txt has "123" in it, and when i run the batch it was do this
xcopy C:\System\here\123\0.jpg
is this possible?
Xcopy C:\Example\123\0.jpg C:\Destination\123\0.jpg
but i have hundreds of lines at a time to do this, and the starting point and folder names are constantly changing. Not the jpg, just the folder that it is in. So i would like to have 2 .txt files, one i can paste a location in and the other a file name
example-
location.txt has "C:\System\here" in it
Files.txt has "123" in it, and when i run the batch it was do this
xcopy C:\System\here\123\0.jpg
is this possible?
Re: Batch File Help Please ( reference a text file )
Code: Select all
@echo off
set /p location=<"location.txt"
set /p files=<"files.txt"
Xcopy "%location%\%files%\0.jpg" "C:\Destination\%files%\0.jpg"
pause
-
- Posts: 19
- Joined: 23 Jul 2013 12:45
Re: Batch File Help Please ( reference a text file )
IT ALMOST WORKED PERFECTLY!!!
Maybe it was my example that wasnt clear enough, the location worked PERFECTLY, however the files.txt will contain a list of hundreds of file names
example
12422
1232456
12323
1231
it worked for the first line of 12422, but it did not work on the rest, i basically want the entire list of folder names in the TXT moved, they will all be in the same location as the location.txt, just a bunch of files.
Maybe it was my example that wasnt clear enough, the location worked PERFECTLY, however the files.txt will contain a list of hundreds of file names
example
12422
1232456
12323
1231
it worked for the first line of 12422, but it did not work on the rest, i basically want the entire list of folder names in the TXT moved, they will all be in the same location as the location.txt, just a bunch of files.
-
- Posts: 19
- Joined: 23 Jul 2013 12:45
Re: Batch File Help Please ( reference a text file )
I got it to work!!! thank you so much!
the problem i am having now is it works in a separate batch file, but when i add the text to my main batch program it will not work??? Is there some way to isolate this script from the rest so it will work within my main batch program? i have tried putting ( ) around the entire script but that did not work...
the problem i am having now is it works in a separate batch file, but when i add the text to my main batch program it will not work??? Is there some way to isolate this script from the rest so it will work within my main batch program? i have tried putting ( ) around the entire script but that did not work...
Re: Batch File Help Please ( reference a text file )
daviddc114 wrote:I got it to work!!! thank you so much!
the problem i am having now is it works in a separate batch file, but when i add the text to my main batch program it will not work??? Is there some way to isolate this script from the rest so it will work within my main batch program? i have tried putting ( ) around the entire script but that did not work...
I am not omniscient. I have no idea what your final code looks like or how you ran it.
Re: Batch File Help Please ( reference a text file )
daviddc114 wrote:So i would like to have 2 .txt files, one i can paste a location in and the other a file name
You got what you asked for, David.
The man of the house, a programmer:
My wife said: "Please go to the store and buy a carton of milk and if they have eggs, get six."
I came back with 6 cartons of milk
She said, "why in the hell did you buy six cartons of milk??"
"They had eggs"