I'm trying to move a bunch of folders from directory A to directory B.
The folders I would like to move have .csvs and .jps inside.
Directory A contains the following files that must remain in directory A (bat, cmd, py, csv, txt). Basically, all subdirectories of Source directory go, while all files stay. Not sure how everyone else would do this?
Visually it looks like this
Directory A
-Folder 1 (to be moved)
-Folder 2 (to be moved)
-Folder 3 (to be moved)
-Folder 4 (to be moved)
-cmd files
-python scripts
-csv files
-bat scripts
My code is below. It fails to move anything returns the following error:
Error 32 - 'Deleting Source Directory' is being used by another process (must be the batch script doing the command below). I'm glad it fails because I don't want to delete the source directory, I want to delete the subdirectories within the source directory. Any ideas?
robocopy /move SOURCE_DIR DESTINATION_DIR /XF *.cmd* *.log* *.py* *.csv* *.bat*
Should I make this a two command script instead? First one copies the subdirectories, and the second deletes them?
Related
I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.
I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.
Example (look at attached image):
I have a folder that contains 1.txt, 2.xml, a sub directory.
And I want to turn all of them into a .zip file.
If possible to get a solution both for windows and Mac.
On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.
On Contents tab there is the list item Command Line Version with the help pages:
Syntax ... Command Line Syntax
Commands ... Command Line Commands
Switches ... Command Line Switches
The target is to compress everything in folder test into a ZIP file with name of the folder as file name.
This could be done for example with the command line:
"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"
This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).
In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.
I have a Directory with many sub-directories in it including one named as OLD. This OLD folder could also be inside any of the sub directories and contains archived files.
Root Directory A
SUB-DIRECTORY A
file1.txt
file2.txt
SUB-DIRECTORY B
file1.txt
file2.txt
OLD
SUB-DIRECTORY C
file1.txt
file2.txt
SUB-DIRECTORY D
file1.txt
OLD
SUB-SUB-DIRECTORY E
file7.txt
OLD
I need to create a job in Talend which shall look for all OLD folders (in main and in sub directory both) and delete the files from that folder. I can use tFilelist to and mask the files to be deleted. But unable to figure out how to configure the job to look for OLD folder in all sub directories and delete those files also.
What you need to do is in the tFileList put your main folder choose check box include sub directories and in the FileList type drop down list choose Directories. Your file mask should be "OLD" or if it is anything more "OLD".
Iterate and use the parameter ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))
to capture your sub directories. Now you can use this folder path in a tFileDelete Which can also delete folders
follow below approach..
Add tFileList and configure to Travers over all the directories.
now use if conndition connection from tFileList
Add tJava and connect with iterator connection
Add tFileDelete after tJava and connect with IF condition.
Add below condition inside if condition.
((String)globalMap.get("tFileList_2_CURRENT_FILEPATH")).contains("OLD")
Now you will get the all files from all the directories above code will give pass to the files which has the "OLD" in there file path.
I have not tested but you can try it.
I have 2 identical folder trees, let's call them C:\First and C:\Second, with many subfolders. C:\First has many XML files in many sub and sub-sub folders. C:\Second just has the folder tree created.
I want to go through all XML files in C:\First\* and put it in it's equivalent place in C:\Second.
But first I want to check if a file with the same name exists in the C:\Current folder (no subfolders there), in which case I will copy the one from C:\Current to the proper sub-sub-sub folder in C:\Second.
In other words, I want to copy the whole structure and files from C:\First to C:\Second but I want to take the latest version that may or may not exist in C:\Current. And, in C:\Current there are many files I don't care about.
Example:
C:\Current has these files:
a.xml
b.xml
1.xml
c.xml
d.xml
e.xml
2.xml
f.xml
g.xml
3.xml
In C:\First I have a.xml, b.xml, c.xml, d.xml, e.xml, f.xml, g.xml spread out in its sub-folders.
I hope I'm not being too confusing...
When a problem is properly stated, the same problem description may serve as specifications to write the program. In your case, you have this description:
I want to go through all XML files in C:\First* and put it in it's
equivalent place in C:\Second.
But first I want to check if a file with the same name exists in the
C:\Current folder
The "But first" doesn't serve to write a program. You just need to write the first things in first place! For example:
I want to go through all XML files in C:\First*. I want to check if a
file with the same name exists in the C:\Current folder in which case
I will copy the one from C:\Current to the proper sub-sub-sub folder
in C:\Second. Otherwise put the file from C:\First in it's equivalent
place in C:\Second.
The pseudo-code below is an example of how your original problem description may be translated into a program:
rem I have 2 identical folder trees, let's call them C:\First and C:\Second, with many subfolders.
rem C:\First has many XML files in many sub and sub-sub folders. C:\Second just has the folder tree created.
rem I want to go through all XML files in C:\First\*
for /R inside C:\First with all *.XML files do (
rem But first I want to check if a file with the same name exists in the C:\Current folder (no subfolders there)
if exist "C:\Current folder\place here just the name of the file from the for command" (
rem in which case I will copy the one from C:\Current to the proper sub-sub-sub folder in C:\Second.
set properFolder=place here the sub-sub-sub folder from the for command
set properFolder=change "C:\First" by "C:\Second" in properFolder
copy "C:\Current folder\just the name" "!properFolder!"
) else (
rem ... and put it in it's equivalent place in C:\Second.
set properFolder=place here the sub-sub-sub folder from the for command
set properFolder=change "C:\First" by "C:\Second" in properFolder
copy "the file from for command" "!properFolder!"
)
)
If you analyze this code you will realize that the lines that get properFolder are the same in both parts, so a simpler method would be to get properFolder just one time before the if command.
You may use this pseudo-code as starting point to write your Batch file.
Hi, I have many zip files located at g:\toto. These zips contain some files. I would like to extract all zip in a same directory (g:\toto\extracted) then rename various files of the zip.
Example 1 :
www_12567.vp.zip : 3 files : alpha.doc, beta.xls, teta.doc
I would like after extraction, files are renamed with the name of the zip
www_12567.vp.alpha.doc, www_12567.vp.beta.xls, www_12567.vp.teta.doc
Example 2 :
www_12.vp.zip : 3 files : al.doc, bea.xls, tta.doc
www_12.vp.al.doc, www_12.vp.bea.xls, www_12.vp.tta.doc
I found this question, but it talks about .txt and the zip contain one file, so, it doesn't work.
Without knowing the contents of the archive you can't know which files to rename, because you are putting them into a directory that may already contain other files.
This, however, would be much easier if there was a dedicated directory to put the files temporarily. Here's how you could use it:
#ECHO OFF
SET "srcdir=G:\toto"
SET "tgtdir=G:\toto\extracted"
SET "tmpdir=G:\toto\extracted-tmp"
FOR %%Z IN ("%srcdir%\*.zip") DO (
unpack "%%Z" with your favourite tool into "%tmpdir%"
FOR %%I IN ("%tmpdir%\*") DO MOVE "%%I" "%tgtdir%\%%~nZ.%%~nxI"
)
Of course, the temporary directory would need to be empty before running the batch file. You could add DEL "%tmpdir%\*" somewhere before the loop to make sure it is.
One other note is, the above assumes that the archives do not contain subdirectories or, at least, that the files are extracted without subdirectories.
UPDATE
If you are using the 7-Zip archiver to work with .zip files, then this is how your extract command might look:
7z e "%%Z" -o"%tmpdir%"
Disclaimer: I'm not an active user of 7-Zip. This is what I used as a reference to come up with the above command:
7-Zip Command-Line Examples
I'm trying to copy a number of files from a directory. I want to include the file path from the base of this particular directory tree, however, I only have a list of the file names to go by. Is there a way to copy either:
a list of files with their directories appended to the beginning in a .txt file
a copy of the folders in the directory with copies of the files placed in their original places in the original directory.
Each file in the directory has a unique name.
I've looked all over google, but the closest I've found is xcopy, which I don't believe is capable of this.
Thanks!
For the second option you can use xcopy /s or robocopy /s. Both are great tools for this kind of job.