I am trying to copy pdf files which are named with KBSMPP*.pdf, just like in Linux. The file also could have more strings, but it is stil a pdf, e.g. KBSMPP_____.pdf
I have many Files, the files are named:
KBSMPP1.pdf
KBSMPP345.pdf
KBSMPPKL.pdf
I don't know how it works. How can I search specific name files?
My code in Batch is:
xcopy "C:\Users\Manfred\Documents\KBSMPP*.pdf" "H:\Users\Hendrik\Documents\Frames"
Another example which I have tried:
ROBOCOPY "C:\Users\Manfred\Documents\KBSMPP*.*pdf" H:\Users\Hendrik\Documents\Frames "KBSMPP*.pdf"
There are several methods.
Using Copy:
Copy "C:\Users\Manfred\Documents\KBSMPP*.pdf" "H:\Users\Hendrik\Documents\Frames\"
Using Robocopy:
ROBOCOPY "C:\Users\Manfred\Documents" "H:\Users\Hendrik\Documents\Frames" KBSMPP*.pdf /MT:32 /B
Using a FOR Loop you can paste into a cmd prompt:
FOR %A IN ( "C:\Users\Manfred\Documents\KBSMPP*.pdf") DO (
COPY "%fa" "H:\Users\Hendrik\Documents\Frames\" )
Related
I am trying to find a way to search a directory for files by name, then copy the found files to an output directory. Because the files will have the same file name, I'm wondering if I can copy the folder structure as well, or alternatively append the filename with its parent folder name (i.e. folder\file.txt becomes folder-file.txt)
The search I'm using is a basic dir call:
dir file.xml /s
Can I do what I'm trying with only cmd? I would be ok using this in a batch script as well, though I believe the syntax is the same.
I would probably do this with robocopy (built in to newer versions of Windows). Something like this should do the trick...
robocopy.exe /S C:\FromDir C:\ToDir file.xml
This will copy the file.xml files that match on c: and keep the folder structure intact, to d:\results
xcopy "c:\file.xml" "d:\results\" /s
I am trying to create a batch file that searches a folder for zipped files, and unzip them. I want the script to search through all the subfolders in the main folder, and unzip everything it finds. It might be a main folder with several subfolders. Some of the subfolders will contain zipped files, but some will not.
The zipped files will look like "filename.r00", "filename.r01", "filename.r02", and so on. One file will have the name "filename.rar", and it is this file that will need to extracted using 7-zip.
Is it possible to write a batch file that does this, and then deletes all the zip files? I have already installed 7-zip, so if it is possible I would like to use it. If anyone could help me write the batch file, it would be much appreciated!
Thanks!
Here you go
for /r C:\Mainfolder %%a in (filename.r*) do (
7z e %%a -o%%a_Extracted
del %%a /f /q
)
After looking at the switches for 7-Zip this might be faster (untested)
7z x filename.r* -o*_Extracted -r
del filename.r* /f /q
Either way they are extracted to a folder with _Extracted at the end, otherwise it will extract them to a folder with the same name as the archive, and when it deletes the files, it may try and delete the folders too.
I have a folder containing many other sub-folders. I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using xcopy for this. The folder structure is as shown below:
FolderB1
FolderB2
FolderB22
File1.txt
File2.txt
File3.txt
I have some .txt files inside FolderB1, along with FolderB2 and FolderB22. I want to copy FolderB2 and FolderB22 and skip .txt files contained in Folder B1
I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of .txt files. Have checked this question too, but did not help.
Also, I want to avoid using del command, since copying all and deleting again would consume time.
Can this be achieved using Robocopy? Exactly similar question is raised here.
Any pointers would be useful. Thanks in advance.
To clarify, I asume you mean to exclude all .txt files in FolderB1, but not exclude .txt located elsewhere.
You can do that with robocopy in two steps. First copy all files except any .txt. And in the second step copy only .txt files, but exclude FolderB1.
robocopy c:\source c:\destination /s /xf *.txt
robocopy c:\source c:\destination *.txt /s /xd c:\source\FolderB1
I have a strange problem with xcopy in Windows XP Professional. I don't know if its a stupid question as I am specifying only a file as the source, so should I even expect any other behavior ? This is it:
I am using xcopy <src> <dest> /s/y.
<src>=C:\sourcefolder\a\b\c\d\something.java and
<dest>=C:\destinationfolder.
Now xcopy copies the file but does not create the directory structure \a\b\c\d\ inside C:\destinationfolder .
what I want is C:\destinationfolder\a\b\c\d\something.java and
what I get is C:\destinationfolder\something.java
I have tried to run it in destination folder C:\destinationfolder by specifying a . for target folder
Tried it without any target in above
There is a script I have which calls xcopy iteratively so I am left with C:\destinationfolder\many java files without any directory structure.
A. Yes I have done xcopy /? to see all options
B. /T also does not create any empty directory structure
C. I can not go to source folder a\b\c\d\ and run xcopy . <dest>
UPDATE
I removed my previous answer on using ROBOCOPY. I believe the following will do what you want using XCOPY.
Assuming your folder structure is like this:
SOURCE = C:\MyJavaStuff\A\B\C\D\something.java
DEST = C:\MyDestination
Run XCOPY like this:
XCOPY C:\MyJavaStuff\something*.java C:\MyDestination /S /E
Note the * in something*.java.
The problem is that you are specifying which file to copy in the source. xcopy won't create the folder structure in this case. However, if you change your call to xcopy to
xcopy *.java C:\myfolder /s/y
it will copy the .java files and the folder structure as well. You need to specify a wildcard for this call to work as you want. If you want only to copy specific files, you will have to adjust the call to xopy, e.g.:
xcopy something.jav* C:\myfolder /s/y
Edit
You say that you get the list of files to copy from another command. If you can output this list of files in a text file, you could do the following:
FOR /F "tokens=* delims=," %F in (d:\test\list.txt) DO xcopy src\%~nxF* .\dest /S /Y
What this command does is read a text file ("d:\test\list.txt" in this case), read every line, and for each file, run xcopy, adding a wildcard at the end of the file name to make sure it creates the folder structure.
I'm assuming here that:
You can get the list of files in a text file, with only the file names (and optinally the paths)
You know the source folder ("C:\sourcefolder" in your example, the folder structure "a\b\c\d" does not need to be known) and can use it in the FOR command.
You can also use the following form:
FOR /F "tokens=* delims=," %F in ('cmd') DO xcopy src\%~nxF* .\dest /S /Y
where cmd needs to be replace with the command you use to generate your list of files to copy.
Note that if you use this FOR command in a batch file, you need to replace %F with %%F (and %~nxF* with %%~nxF*).
I had a look at the xcopy switches and you can copy the directory structure with /T, although that doesn't copy empty directories you can override this with /E. So your command would look like this:
xcopy C:\sourcefolder\a\b\c\d\something.java C:\destinationfolder /T /E /S /Y
Hope this helps!
In order to get C:\destinationfolder\a\b\c\d\something.java XCOPY needs to know how much of C:\sourcefolder\a\b\c\d\something.java to duplicate.
You can use:
C:
cd \sourcefolder
XCOPY something.java* C:\destinationfolder\ /S
Just be aware that this may have the side effect of also copying C:\sourcefolder\oops\something.java to C:\destinationfolder\oops\something.java as well as any other matches for something*.java under C:\sourcefolder\.
It seems to me that xcopy is typically used for copying directory trees, not single files (though it can work). And, xcopy will recreate the directory structure under the source folder in the target folder. If xcopy is given the /i switch, the target folder is assumed to be a directory. It will be created if it does not exist, even if there are multiple parents that need to be created.
You have C:\MyJavaStuff\A\B\C\D\something.java - that is your source. You want to end up with something.java not in C:\destinationfolder, but in C:\destinationfolder\A\B\C\D - so that is your target. You don't even have C:\destinationfolder. That is OK, with /i the entire path will be created.
xcopy /i c:\MyJavaStuff\A\B\C\D\something.java C:\destinationfolder\A\B\C\D
If something.java were the only file under C:\MyJavaStuff, you could also use
xcopy /sei c:\MyJavaStuff C:\destinationfolder
That would recreate the entire tree structure, copying your file. But if there are other files (and folders) under MyJavaStuff they would also be copied.
I have written a very similar batch file using xcopy. Perhaps what I did will help you.
This is the command I used:
xcopy "c:\Data Files\Dave's Data\*.*" "m:\Dave's Data" /R/D /E/H
In this case, Dave's Data on the source contains an entire directory tree containing at least 50,000 files & exceeding 75GB data. It runs perfectly on Windows XP
I found /T was unnecessary as the directory tree is copied. I also found /S was unnecessary as /E copied directories & sub-directories including empty ones. I included /R to copy & overwrite read only files on the destination. /H copied hidden directories. /D copied only newer files. I use this as a daily backup tool for my data.
The only problem I have is while this command will work on Windows 7 the first time, it will not work on subsequent runs when the destination directory tree exists. I suspect this is due to a privilege issue as the xcopy command will work on subsequent runs on Windows 7 within a cmd.exe window.
I have a folder containing 1000+ xml files. I need to modify these xml files, for which I am using xslt.
Now the problem that I am facing is that I want to use batch script to do this modification recursively for all the xml files in the folder, rather than doing it manually. How can I do it using batch script?
It would be helpful if anybody could tell me how can I read all the xml files present in a folder and copy them to another folder with the same name.
Transformation:
for /r c:\your_root_folder\ %f in (*.xml) do your_transform_command %f
Copy:
copy *.xml c:\your_target_folder\.
Assuming you are using DOS batch ...
A simple copy operation will work:
prompt> copy *.xml destinationDir
To loop and process files individually, we use:
for %%R in (*) do (
...
)
read this
HELP XCOPY,
and this
HELP FOR.
and try this
XCOPY \source\*.xml \destination /S
and try this
FOR %a IN (\source\*.xml) DO echo %a
and now read
HELP CALL
and read
HELP SET
and try this
FOR %a in (\source\*.xml) DO CALL youraction %~na
and by the time you understand what happened you are ready to achieve your goal.