I need to write a batch file that uploads two files via FTP to different folders.
Example: filename_0001.txt copy to folder1 on server1 filename_0002 copy to folder2 on server1.
The names of target files are fixed.
My current batch file uploads only the first file that has the lower number -the only difference in the filenames are the numbers, that are changed daily.
user name >>script.txt
%1 >>script.txt (password as parameter to batch file)
put filename_????.txt folder1
ftp -s:script.txt [server name]
How can the other file with higher number be uploaded? I thought of checking the file names and then put them in the script. Can anyone tell any command to do that?
I need something like this:
put filename_????+1.txt folder2
Prepare a text file (folders.txt) with a sorted list of folders to use, like:
folderA
folderB
folderC
folderD
From a batch file save a sorted list of files to upload to another file (files.txt). Merge the two files together as described in question Combining multiple text files into one.
The code would be like:
#echo off
dir /ON /B filename_????.txt > files.txt
setlocal EnableDelayedExpansion
3< folders.txt (for /F "delims=" %%a in (files.txt) do (
set /P FOLDER=<&3
echo put %%a !FOLDER!
))
The output will be like:
put filename_4100.txt folderA
put filename_4101.txt folderB
put filename_4102.txt folderC
put filename_4103.txt folderD
It won't work when number of digits in filenames is different, as filename_10000.txt will be sorted before filename_9999.txt. For possible improvement, see Naturally Sort Files in Batch
Related
I want to move several thousand files (.jpg and .pdf) from one location to another and then rename each file.
My 'copy_rename_docs.csv' input file contains two columns:
the first column containing the original path AND file names for each file that I want to move and rename
and the second column containing the new paths AND file names that I want to move and rename each file to
like this:
\\myapp\data\e3\9b\e39bf5e8d745833418d3edcd97c6c7589716970b,\\myapp\test_migration\e3\9b\Test File-xxx - SS1.pdf
\\myapp\data\09\f5\09f58d1a1345f67a36154e99ffedb27308fa4292,\\myapp\test_migration\09\f5\nxf7.pdf
so "e39bf5e8d745833418d3edcd97c6c7589716970b" is a SHA1 hash of "Test File-xxx - SS1.pdf"
To copy and rename the files I tried this batch file:
#echo off
FOR /F "tokens=1,2 delims=," %%a IN (copy_rename_docs.csv) DO (xcopy /e /i "%%a" "%%b\*")
pause
exit
But instead of copying and renaming the files to this:
\\myapp\test_migration\e3\9b\Test File-xxx - SS1.pdf
\\myapp\test_migration\09\f5\nxf7.pdf
It is creating a FOLDER for each file with the FILE names as the FOLDER names and copying the files with their original file names into each FOLDER, like this:
\\myapp\test_migration\e3\9b\Test File-xxx - SS1.pdf\e39bf5e8d745833418d3edcd97c6c7589716970b
\\myapp\test_migration\09\f5\nxf7.pdf\09f58d1a1345f67a36154e99ffedb27308fa4292
What I want is:
\\myapp\test_migration\e3\9b\Test File-xxx - SS1.pdf
\\myapp\test_migration\09\f5\nxf7.pdf
What's wrong with my batch file?
And is xcopy the best tool for this?
for /L %%f in (1,1,10) do copy File1.txt %%f.txt
this code does the job very well, but I'm trying to understand how to change it to make it read
subfolders, so that I don't have to keep moving the batch file to every folder
I saw this, but not really sure how to put it together
#echo off
SET "sourcedir=C:\Users\user\Desktop\Main\Original"
SET "destdir=C:\Users\user\Desktop\Main\Copied"
for /L %%f in ('dir /s 1,1,10) do copy *.txt %%f.txt
in the section - copy *.txt %%f - I put a * so that it can only look for .txt files, but this action
slows down the coping and then stops working.
I know my code is a mess, just trying to put something together
I have many Subfolders and each folder has 1 txt file in it with all random names
and I need to make multiple copies of each file.txt in each folder
I have so many subfolders that it would literally take me months of time to get all files copied
and by then I would have many more new files to work on
so getting this copier to read Subfolders is like top priority for me.
I would like help putting this together and then explaining how it links
because I'm interested in applying the Set and dir to other batch file I have
Please any details on this will be much appreciated
I was told to look into xcopy and robocopy, but I have no idea were to add a counter
#echo off
for /1 %f in (1,1,10) do xcopy "C:\Sources" "C:\Target" /c /d /i /y
exit
So I have this that reads from source and dumps in main folder where the batch is
Option 1)
for /L %%f in (1,1,10) do xcopy "C:\Source Address\*.txt" %%f.txt
Option 2)
for /L %%f in (1,1,10) do xcopy "C:\Source Address\" "C:\Destination Address\ %%f.txt"
The thing I don't like is that is asks me a question
and I have over 10,000 txt files, I can't sit here and press F for Filename
10,000 times, can we disable that
OK, so I got this working
all I need help with is were to add this /c /d /i /y
I am still trying to get it to read Subfolders with the batch sitting
in the main folder and me not having to move files back and forth
Option 3)
for /L %%f in (1,1,110) do copy "C:\Source Address\*.txt" %%f.txt`
This works well with the Source and the wild card #magoo told me to add
the Source before the .txt file
But with this code I would still have to open hundreds of folders and move
the file to the source run the copier and then move back all copied files
Still need help with Subfolders
for /L %%f in (1,1,10) do copy File1.txt %%f.txt
will vary %%f from 1 (the first number in the parenthesised list) to 10 (the last) in steps of 1 (the middle) and will therefore copy file1.txt to 10 separate files, 1.txt to 10.txt.
Since there are no paths specified, the copy will be performed from file1.txt in the current directory to 1.txt .. 10.txt in the current directory.
If you were to put your batch file in any directory that is mentioned in the path variable (just execute path at the prompt to show it) then no matter where the current directory is, you could just use that batch filename to execute the batch, and the files would be created by copying file1.txt in the now-current directory to 1.txt .. 10.txt in the now-current directory - if file1.txt exists in the now-current directory, and if not, it will generate error messages reporting that the source file is missing.
If you were to replace file1.txt in the batch with "x:\wherever\file1.txt" then the file would be copied specifically from the file "x:\wherever\file1.txt" regardless of whether file1.txt exists in the now-current directory. (And please get used to "quoting file or pathnames" as it will avoid a whole slough of problems when you tackle names containing spaces and some other special characters).
I have no idea how for /L %%f in ('dir /s 1,1,10) do is supposed to work since according to Hoyle, the first element in the parenthesised list should be a number. I'd suggest that we have a small transcription problem here.
Th slower and slower problem - yes, understandable. You are creating more and more .txt files, and copying all of them to a new destination...
Perhaps referring to This response and question might show how to solve your subdirectory-scan issue.
I need help creating a batch file to find multiple files named the same thing in 100's of files and replace the with a different file...
Alternatively, is there a program that will do this if I select the 2 different files that will search and replace them...
Find file from computer Pairing = High School DxD - Kuroka.png
Replace file with Pairing = High School DxD - Kuroka (F).jpg
Since you never provided the basic information such as What directory you wish to start a search from or You wish to convert or just rename, I will assume you wish to search your photo's folder (Including sub-directories) and simply rename file.jpg to file.png.
To search photo's and all its directories we can use the FOR /R to search for all .jpg files and DO to address the action. The script bellow will do the following.
Search and replace all .jpg extensions to .png in the photo folder directory
Batch Script:
#ECHO ON
#CD C:\Users\%username%\Pictures
For /r %%A In (*.jpg *.jpeg) Do ren "%%A" "*.png"
goto :eof
I have 10-20 directories with a number of files inside in each folder.
I want to join in a single file every pack of files inside each folder so if I have 20 folders with 2300 files I want 20 joined files.
Example
INPUT
folder1 - 500 files
folder2 - 340 files
folder3 - 5 files
OUTPUT REQUEST
folder1.txt (500 joined files)
folder2.txt (340 joined files)
folder3.txt (5 joined files)
But I have many folders so I try to find a .bat command to create automatically this operations.
VIDEO: what i want
Assuming each of your files is text file with a newline terminator at the end of each final line, then you can use the following:
for %%F in ("folder1" "folder2" "folder3") do >"%%F.txt" type "%%~F\*"
The name of each file will be output to the screen via stderr.
If you want to hide the file names:
for %%F in ("folder1" "folder2" "folder3") do >"%%F.txt" 2>nul type "%%~F\*"
If you want the file names to be included in the text file output:
for %%F in ("folder1" "folder2" "folder3") do >"%%F.txt" 2>&1 type "%%~F\*"
IF you want to process all folders within your current directory, then change the FOR command for any of the commands listed above to look like:
for /D %%F in (*) do ...
Can anyone assist me in writing a batch script that searches for file names and outputs the location of the files to a text file. Example I have a file called list.txt located in a folder, C:\LocateFiles\list.txt. Located in the list.txt file are about 25 file names that I wish to determine if they are anywhere on the C:\ drive. If it locates any of the file names identified in the file list.txt it will output the path of all files found to a single file in C:\LocatedFiles\results.txt.
A million thanks,
Johnny Mac
#ECHO OFF
FOR /F %%F IN (C:\LocateFiles\List.txt) DO DIR /s/p/b %%F.* >> C:\LocateFiles\finds.txt
Save that as LocateFiles.cmd and place it in whichever directory you wish to search, note that C:\ is very large and will take quite a while! as in, forever, seriously, i really wouldnt, your call...
the file finds.txt will have the entire path for any file that matches up to the file names listed in List.txt
Also note, this finds files of any extension, but the filename itself must match exactly to whats in List.txt
The solution below search the files in the current directory just once, so it run faster.
#echo off
dir /S /B /A-D | findstr /I /G:C:\LocateFiles\list.txt > C:\LocatedFiles\results.txt
EDIT: New method added
The method below may run even faster. It is necessary to complete a timing test.
#echo off
setlocal EnableDelayedExpansion
rem Read file names from file list and assemble a long string with this format:
rem "filename1.ext*" "filename2.ext*" ...
set "fileList="
for /F "delims=" %%a in (C:\LocateFiles\list.txt) do set fileList=!fileList! "%%a*"
rem Search the files from current directory downwards
(for /R %%a in (%fileList%) do echo %%a) > C:\LocatedFiles\results.txt