Move files to a folder if filename contains folder name - move

I am trying to move files of various extensions to a folder if the filename contains the folder name.
Simple example: I have several files such as Fox-1.doc, Fox-2.doc, etc. I have a folder named Fox. I'm trying to move the files into the folder Fox if folder name is contained in the filename.
I tried to modify the code in the following post but I was not successful.
Move files into existing folders containing part of the filename
Any pointers is appreciated.

If you are using code for doing this try getting the filename and filter from the .contains() method often found in Strings.
If you are using Linux command line I think this could work
mv *fox* destination_path/
For Powershell I found this thread that could help you:
powershell to move files based on part of file name
All you'd have to do is create the .ps1 with the modified script.

Related

Batch re-name files in multiple directories on MacOS

I have around 500 JSON files sitting in their own directories that I need to re-name.
Every JSON file has the name, "list.json".
So what I need is a batch file operation for MacOS of some sort that will look in all the directories for files matching "list.json" and change the name to match name of the directory the file is sitting in. What kind of script do I need to do this?

How to rename a string in all file types?

How would I rename a string in all file types not just one file type like .txt in Windows 10? Like for example if all my file names were named Bear-(number) but there are lots of different file types like .html, .php, .pdf, .css, & more how could I rename them all? I don't want to have to list all the file types in the folder... Your help would be appreciated.
In windows 10, use command prompt by clicking on the windows button and typing in cmd
Switch to the directroy you have your files in - for example if they are in a directory called 'temp' enter cd temp.
Another example - if the files are in a nested folder like c:\temp\test - enter cd c:\temp\test
If they are on another drive, you will need to change to that drive by specifying the drive letter and then a colon... eg 'e:'
rename all files rename Bear-00001.* Bear-00002.*
The * at the end will preserve the file extension while changing the file name itself
hth

creating a batch file

I would like to creat a batch file that will recognise folders date moidified in a network drive and then copy them to another network drive
while I was searching I found way to do that to files, but I need it for folders
I didn't find a way to do that
Sadly, you didn't say which method you'd found. If that method selects the files using a DIR.../a-d... structure for instance, then omit the - before the d and directories matching the selected pattern rather than files would be processed.
To create a batch file just get notepad++ and save as a .bat, is that what you meant? or did you want a certain type of Batch file, because I didn't think there was another type unless you count Command prompt and Notepad++ different?
Forfiles may be helpful, or robocopy
This will create a mirror backup in the destination folder. If files are deleted in the source then they will also be deleted in the destination.
#echo off
robocopy "\\172.172.172.10\folder" "\\172.172.172.2\destination" /mir

How can a watir script open a file in a different folder?

I am having trouble opening a .txt file that is in a different set of folders than where I have my .rb test script. I have a file structure of different test categories and then one generic folder that holds data files like .txt and Excel files.
Example:
Test Scripts -> Data This is where the data files are saved
Test Scripts -> Home Page -> Checkout This is where the .rb test file is
I am using this to open the .txt file now:
File.open("Data/activeSites.txt")
when the .rb is in the same folder as the Data folder.
Any suggestions?
If I correctly understand what you're asking, the issue is that you want to move your Ruby script from TestScripts/ to TestScripts/HomePage/Checkout/ and aren't sure how to refer to the activeSites.txt file from there. Is that correct?
If so, you just need to know that ../ means "the parent directory", so you can use:
File.open("../../Data/activeSites.txt")
The first ../ refers to the Home Page folder, then the second takes you up one more level to the Test Scripts folder.

DOS Commands- Excluding files in a folder in xcopy

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. I am facing following problem:
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.
Alternate method or other pointers for the same would be a great help. Thanks in advance.
What you could try to do is to hide the files you don't want to copy, then execute the xcopy, and then unhide the files again.
Look at my answer of question Windows batch script to delete everything in a folder except one. That question was related do deleting files (excluding some files), but you can probably use the same trick for xcopy-ing files.

Resources