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
Related
I'm trying to create a batch file that can delete .xmlb files is there is a .engb file of the same name in the same folder. I want it to work so that it can check the folder where the batch file is placed as well as all of the sub-folders. I found this question where someone pointed out how to do this in a single folder, but I'm trying to do it in every sub folder. Here's what I have so far:
#echo off
for /r %%I in (*.xmlb) do (
if exist %%~pnI.engb del %%I
)
pause
It gives me a "the system cannot find the path specified" error. I tried changing del with echo, and when I do that it does manage to display the names of the .xmlb files (with .engb extensions), so I'm assuming it can actually find them and my syntax is off somewhere. If I try to use %%~nI like the original code, it won't do anything (because the .engb files are in the same folders as the .xmlb files). I'm sure I'm probably missing some small thing that's preventing it from deleting the right files. Any help is appreciated! I'm attaching two screenshots: one with the batch file in a folder, and then one of the sub-folders that contains .xmlb and .engb files. So in the jungle1, jungle2, and jungle3 folders I want to keep the .engb files and remove any .xmlb files with the same names as .engb files
I have two files in two different folders. I want to move/copy a file in first folder to second folder. If the same file names exist i want to change older file name with older_filename and move/copy new file to same directory. How can i do it?
For example I have a zip file named B FOLDER and i am going to unzip that zip folder in TEMP FOLDER then i will have almost 10 .txt files in TEMP FOLDER. Then i have a TARGET FOLDER that .txt files going to move in TARGET FOLDER from TEMP FOLDER. My question is, that files in TEMP FOLDER and TARGET FOLDER have the same name. I want to rename the files in TARGET FOLDER with old_filename then move to files in TEMP FOLDER to TARGET FOLDER without changing name. Thats what i want, if it is not unclear, sorry :) Really i tried my best.
Best regards.
EDIT 1:
Hi again. Thanks for helps it is really helpfull. I am trying a new code here:
forfiles /P C:\.... /S /M a1.txt /C "cmd /c rename #path old_#fname.txt"
Above code is changing file names in TEMP FOLDERs. But i want to change file names in TARGET FOLDERs. How can i do it visa versa?
how about that? May be it could help to me. How can i go with that code?
I am trying to do an FTP using a .bat file. Now the location I'm taking from will partially match the location on the main drive. I am doing an mget * from that location.
Example: \...\...\Folder1\Folder2
Now on my system, I have folder location \....\....\Folder1\Folder2
I want to match those for the script. Right now I'm trying to use
SET MYDIR=%cd%
set MYDIR1=%MYDIR:~41,7%
for %%f in (%MYDIR1%) do set myfolder=%%~nxf
echo %myfolder%
This gets me the last folder, (Folder2). However the folders are going to be different, I'm placing the .bat file in different folders to do the same thing so I want it to correspond to the different directories no matter the size of the folder name, so I can't use a hardcoded subscript. So then I thought maybe get name of folder2 and then delete it from the string, but I'm having trouble deleting the variable with folder2 text from the string. I can delete specific string from the text, however it won't know from one folder to the next what the string is going to be.
Suggestions? I basically want the last TWO folders as variables so I can pass them to my script that will drawl from the server.
You can get the child and parent directory names of the current directory using the FOR command.
for %%G in ("%cd%\.") do set child=%%~nxG
for %%G in ("%cd%\..") do set parent=%%~nxG
I want a batch file to check for a certain files in a folder and all of its subdirectories and if that file is found I want to copy the folder in which the file sits.
How can I achieve it? Can anyone help?
You can try something like this:
#echo off
for /R "full_path_to_folder_with_subfolders" %%A IN (filename_you_want_to_check) do (
copy %%~FA "full_path_you_want_file_to_be_copied"
)
NOTES:
full_path_to_folder_with_subfolders should be replaced with the FULL PATH of folder which contains the subfolders in which you want to search the certain files.
filename_you_want_to_check is only ONE certain file you want EXCEPT if your files have a common suffix, for example you have files a1.txt and a2.txt (ONLY IF these files will be copied in the same location) replace filename_you_want_to_check with a*.txt.
full_path_you_want_file_to_be_copied is the FULL PATH where your certain files (filename_you_want_to_check) should be copied.
Hope this helps!
I'm trying to copy files from one folder to another folder but I only copy the files from source folder if that file exists in lookup folder.
#ECHO off
For ℅℅a in (℅1\*) do (
Set file = "℅2\℅℅~na℅℅~xa"
If exist ℅file℅ (
Echo yes
// Copy to destination folder
)
Else(
Echo no
)
)
I am running it like
"Copy.bat sourcefolder lookupfolder" destinationfolder
I just started batch script today and I Donno what's wrong but I have two folder source folder and look up folder in folder source I placed to files a.txt and b.txt and in folder lookup I have only b.txt but when I run its printing yes 2 times although a.txt doesn't exist in lookup up
The code you need is this:
For %%F in (%1\*) do (
If Exist %2\%%~nxF (
copy %%F %3\%%~nxF
)
)
So if you save this to a Copy.bat file and call from cmd:Copy.bat C:\a C:\b C:\c the files from folder a that also exist in folder b will be copied in folder c.
Explanation of symbols:
%%F stores the path of the current file that is parsed from the folder (eg C:\a\a.txt)
%%~nxF stores only the name of the file (eg a.txt)
%1 stores the value of your first parameter (eg C:\a)
%2 stores the value of your second parameter (eg C:\b)
%3 stores the value of your third parameter (eg C:\c)
For more information about batch commands visit this link: http://ss64.com/nt/
I hope this was helpful :)