Find multiple files with unique file names and move them - batch-file

Im looking to get some helt creating a BAT file.
I do not have a lot of knowledge about this from before.
The situation:
I have a folder containing about 48 000 pdf files.
I have a csv file containing all the file names (aprox 15000 unique file names) i want to separate and move to another folder.
The files are named like this: 0723850734;0732332262;0723846680;0736187285;0733628507.... and so on.
I created this .BAT file to copy one file:
copy /-y "D:\Scrive\Data\Done\PDF\0723850734.pdf" "D:\Scrive\Data\Done\Telenoravtal"
pause
How can i add all my file names i want to copy/move?

This is more a hack or a workaround than a real solution.
You can open the .csv file in Excel and create template using first part of your code in Column A and drag it as far as you need then in Column B having the file name and in Column C having the rest of your code.
_____________Column A _____________|__Column B__|______________Column C____________________
copy /-y "D:\Scrive\Data\Done\PDF\ | 0723850734 | .pdf" "D:\Scrive\Data\Done\Telenoravtal"
copy /-y "D:\Scrive\Data\Done\PDF\ | 0000000000 | .pdf" "D:\Scrive\Data\Done\Telenoravtal"
copy /-y "D:\Scrive\Data\Done\PDF\ | 1234567890 | .pdf" "D:\Scrive\Data\Done\Telenoravtal"
copy /-y "D:\Scrive\Data\Done\PDF\ | 0987654321 | .pdf" "D:\Scrive\Data\Done\Telenoravtal"
Afterwords just copy the results to text editor, remove extra spaces and your bat script is done.

Related

Copy multiple pdf files into another directory and every file creating folder with its name

I have a folder with around 150 pdf files. I would like to create folders in the name of the 150 files. After that I would like the pdf file to be moved to its respective folder.Can its possible in cmd or any exe file?
Example
E:\
|______ abc.pdf
|______ cde.pdf
|______ efg.pdf
F:\backup\
|______ abc
|____abc.pdf
|______ cde
|____cde.pdf
|______ efg
|____efg.pdf
not tested
#echo off
set "source=E:\"
set "target=F:\bckp"
for %%a in ("%source%*pdf") do (
mkdir "%target%\%%~na"
copy "%%~fa" "%target%\%%~na"
)

Batch file - rename folder within folder but do not know folder name

Hi hope someone can advise:
I extract a folder using 7-zip to a folder called xyz
Inside xyz it then holds the name of the folder I extracted but this changes based on each extraction so cannot hard code my batch file, this subfolder (call it abc [The extraction only every contains 1 folder]) then abc contains standard folders I need to copy to another location.
The problem I have is that I need to either rename the abc to a known items so I can set my path variable or I need to be able to access it regardless of its name and then copy sub folders out to where I need them
My attempts to copy the contents of abc or rename (move) folder abc have failed any suggestions appropriated, below is what I have already tried
Attempt to copy folder contents
c:\xyz>xcopy c:\xyz*\ c:\newlocation
c:\xyz>xcopy c:\xyz** c:\newlocation
Attempt to rename the abc folder
c:\xyz>dir /o-n move "*" c:\xyz\newname
Thanks
Andy
Rename the subfolder of xyz with unknown name to a fixed name first:
for %%g in (xyz) do ren %%g fixed

Batch to read filenames from a file, move them to another dir and list in a text file any that failed

I have a directory of 15,000 images, but only use 1500. I used excel to creaet a list of commands to move each of the 1500 images used to a new folder.
The problem is that only 1200 images were copied, leaving 300 images that we need to create or find.
I am trying to do the following:
File1 has a list of filenames
File2 is to list the filenames that are not avilable
for each filename in file1, read and move the file to another folder. If there is an error (no image to move), write that image name in another file, so we have a list of the 300 images we need to find.
Thanks for any help. I have a little batch experience, but this is a bit over my head.
for /f "delims=" %%a in (excel_file.txt) do if exist "%%a" (move "%%a" "destinationdirectoryname") else (echo %%a>>cantfindthisfile.txt)
Not that hard...

join files inside every folder using batch command

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 ...

How to overwrite files with names starting from nl_ with sp_

I have folder A and B. Folder A has files like: a.mp3 and a.txt and folder B has: b.mp3 and b.txt. What I want to do here is copy and rename the content of the folder A to B so that the files can be overwritten.
Here is an example code on how to overwrite and keep the same file name in folder B:
XCOPY /HECY A\a.txt B\b.txt
ButI don't want to type all the file names to copy and overwrite the files in folder B.
Any help will be appreciated.
This should work. It will copy all A\nl_*.* files to B\, renaming the nl to sp and overwriting the files.
setlocal enabledelayedexpansion
for %%a in (A\nl_*.*) do (
set file=%%~nxa
set file=!file:~2!
xcopy /hecyi "%%a" "B\sp!file!"
)
Renames a file/directory or files/directories.
RENAME [drive:][path][directoryname1 | filename1] [directoryname2 | filename2]
REN [drive:][path][directoryname1 | filename1] [directoryname2 | filename2]
Example
to rename a directory "sampel" to "sample"
rename c:\sampel sample
to rename all text files to files with .bak extension.
rename *.txt *.bak
to rename all files in a particular folder with specific prefix(eg: 1_NEW)
rename * 1_NEW*
4.Rename the file "normal sample.txt" to "example sample.txt". Whenever dealing with a file or directory with a space, it must be surrounded with quotes. Otherwise you'll get the "The syntax of the command is incorrect." error.
rename "normal sample.txt" "example sample.txt"
You may do that directly with xcopy /HECYI A\nl_*.* B\sp_*.* command:
C:>dir A /b
nl_t.txt
nl_test.txt
nl_test.xyz
nl_testLarge.txt
C:>dir B /b
C:>xcopy A\nl_*.* B\sp_*.*
A\nl_t.txt
A\nl_test.txt
A\nl_test.xyz
A\nl_testLarge.txt
4 File(s) copied
C:>dir B /b
sp_t.txt
sp_test.txt
sp_test.xyz
sp_testLarge.txt

Resources