I already searched but I dind´t find a script to do what I need. Need help:
I have the situation:
Parent Folder 1
[file 1]
[file 2]
[subfolder 1]
[file 5]
[file 6]
Parent Folder 2
[file 7]
[file 8]
subfolder 2
[file 7]
Parent Folder 3
Subfolder 3
Subfolder 4
Subfolder 5
[File 8]
I just need to eliminate all subfolders and move files to parent. I already tested a script in .bat file, worked, but it need to be one by one parent folder. I it´s hundreds of parents folders.
I mean: I just need first level to keep strtucture.
I found this:
:loop for /d %%D in (%1\*) do (move "%%D\*" %1\ && rmdir "%%D") SHIFT set PARAMS=%1 if not %PARAMS%!==! goto loop
I just dragNdrop my folders and works. BUT....
Only works with first level of subfolder. I need to go deep to a few more subfolders levels.
Any ideas to improve this?
Related
Total noob question here, but I want to copy every file but file1.txt from 1 directory (i am not in this directory) to another directory using wildcards specificatlly using *
Any help?
I am trying to move 2 files from current directory (/base/level1/level2) to one directory below (/base/level1)
Is there any easier command other than mv file1 /base/level1 ? I'm trying to understand if we have some command that move it to a specific level up or down in the current folder structure.
TIA!
My solution to this one is navigating to the path where I want to move the file and run the following command.
cp ./level2/file1 .
or
cp ./file1 ./level2/file1
Please share other solutions as well
Thanks,
AMK
You could use wildcards if the 2 files have something uniquely in common.
ie. mv file*.ext path/to/new/dest/
This will move all files starting with "file" and ending with the extension ".ext" to the destination. Have a look at this and this which will explain wildcards a bit more
You can always use .. for "one directory up".
And you can give more than 2 arguments to mv, the last always being the destination.
So mv file1 file2 .. would move those 2 files a directory up.
Or mv * .. to move all files.
I am trying to create a folder using batch file. The folder name should be in a format - yyyymmdd-hhmm .I got started with the below code but I get yyyymmdd- as one folder and hhmm as another folder. But when I tried it after 13.00 hrs I get yyyymmdd-hhmm format. Why is there a different behaviour during 9:45 in the morning. I don't know. Any help appreciated.
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
mkdir %mydate%-%mytime%
I get 1 folder -> 20160810- and another folder -> 945.
"I get 1 folder -> 20160810- and another folder -> 945."
That's because of the space, so mkdir sees two parameters and so creates two folders.
Either put qoutes around the new foldername
mkdir "%mydate%-%mytime%"`
or (maybe better) replace the space with a zero:
mkdir %mydate%-%mytime: =0%
putting qoutes around anyway doesn't harm:
mkdir "%mydate%-%mytime: =0%"
(btw: there is a way to get a date-time-string independent of local settings)
I realise it is likely the each of the requirements listed below is available individually within the forum here but I am struggling to bring it all together (if at all possible!).
Hoping someone has the patience and time to point me in right direction to make this happen.
What I need to do is the following:
Scan a directory (and all sub-directories) for a particular filename
NOTE: Whilst there are many files within the sub-directories with the filename in question, we only wish to target those in a sub-directory with a suffix of JERRY
ie. In the below example the files indicated by the arrow would be targeted
ONE\NEW1-JERRY\FILENAME.TXT <----
ONE\NEW1-TOM\FILENAME.TXT
ONE\NEW1-SYLVESTER\FILENAME.TXT
TWO\NEW2-JERRY\FILENAME.TXT <----
TWO\NEW2-TOM\FILENAME.TXT
TWO\NEW2-SYLVESTER\FILENAME.TXT
THREE\NEW3-JERRY\FILENAME.TXT <----
THREE\NEW3-TOM\FILENAME.TXT
THREE\NEW3-SYLVESTER\FILENAME.TXT
FOUR\NEW4-JERRY\FILENAME.TXT <----
FOUR\NEW4-TOM\FILENAME.TXT
FOUR\NEW4-SYLVESTER\FILENAME.TXT
When file is found matching the filename and is within the sub-directory listed above take a copy of the file (to remain in same directory) & rename based on the following criteria:
a) Created date/time
b) Certain content within the file
The content in the file is always located on ROW 8 and it is the first 9 characters
Original filename: FILENAME.txt
Finished Product: FILENAME-20121129#1300-123456789.txt
Thanks in advance!
you should tell us what have you tried so far and what are your mains problems...
try this :
(remove the -whatif flag to actually copy files)
#list dir & subdirs
ls c:\ -recurse |
Foreach {
#find subdirs named JERRY
if($_.PSIsContainer -and $_.name -match "JERRY"){
ls $_.fullname -filter 'FILENAME*' |
Foreach{
$fcontent=get-Content $_.FullName
$content=$fcontent[7].Substring(0,9)
$newName=Get-Date -UFormat "%Y%m%d"
$destination="$($_.Directory)\$newName#$content.txt"
write-verbose $destination
Copy-Item $_.FullName -Destination $destination -WhatIf
}
}
}
I have a directory structure something like :
/etc/home/d1/d2/d3/d4
The last directory d4 contains some files so it is not empty.
But by mistake I forgot to create one more directory in between say d0
So I need to change my directory structure to :
/etc/home/d0/d1/d2/d3/d4
So my question is - is there any way to introduce this new directory in existing path or I have to do all the donkey work? :P
Create a directory under your home directory with name d0. Then use the mv command to move d1 to d0. All directories and files under d1 should get moved to d0 giving you the desired structure.
mkdir /etc/home/d0
mv /etc/home/d1 /etc/home/d0
This is quite different from the single command (when /etc/home/d0 does not exist as a directory):
mv /etc/home/d1 /etc/home/d0
That might be a little confusing. The first creates a directory and moves the hierarchy into it. The second just renames one level in the hierarchy, which was not what you wanted.