File to Folder script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File to Folder script
# 1  
Old 01-18-2013
Code File to Folder script

I am trying to write a linux shell script that will take every file in a folder
/home/user/desktop/fileme
and place it in a folder with the same name as the folder

before
/home/user/desktop/fileme/stuff.txt
/home/user/desktop/fileme/other.avi
/home/user/desktop/fileme/last.jpg

after
/home/user/desktop/fileme/stuff/stuff.txt
/home/user/desktop/fileme/other/other.avi
/home/user/desktop/fileme/last/last.jpg


This seems to be the closest I have gotten

Code:
#!/bin/bash
for filename in /home/user/desktop/fileme/*
do
	mkdir "$filename"
	mv "$filename" /home/user/desktop/fileme/"$filename"
done

Ultimatly id also id like to keep the file extenuation in the folder name striping out the . before the file extention and replacing it with a # or some other special character but really any help would be appreciated

before
/home/user/desktop/fileme/stuff.txt
/home/user/desktop/fileme/other.avi
/home/user/desktop/fileme/last.jpg

after
/home/user/desktop/fileme/stuff#txt/stuff.txt
/home/user/desktop/fileme/other#avi/other.avi
/home/user/desktop/fileme/last#jpg/last.jpg

Any help with code or pointing me in the right directions would be greatly appreciated.
You can ignore my partial solution if you have a better one
# 2  
Old 01-18-2013
Here is a BASH script:
Code:
#!/bin/bash

dir="/home/user/desktop/fileme/"

for file in ${dir}/*
do
        echo mkdir -p "${file/./#}"
        echo mv "${file}" "${file/./#}/"
done

Note: Remove those highlighted echo if the output is looking good.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 01-18-2013
Works perfectly thanks a bunch Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Peer Review File/Folder Script

Hello *nix friends, I've written a shell script that allow web admin's to copy file/folder from a development site to the production site. It's more or less a poor man SVN. I'm posting the script here because I was able to get many questions answered through this forum and also, I want to... (4 Replies)
Discussion started by: rwhite35
4 Replies

3. Shell Programming and Scripting

Bash script for new file in ftp folder

Hello, I'm trying to make a bash script that send me e-mail if there is any new file in my ftp folder. cat inotify.sh #!/bin/sh /usr/bin/inotifywait -e create \ -mrq /home/mrowcp | while read line; do echo -n "$line " >> /var/log/inotify.log echo `date | cut -d " " -f1-4` >>... (3 Replies)
Discussion started by: mrowcp
3 Replies

4. Shell Programming and Scripting

Script to Identify if folder has a file in it

Hi everyone I am new to the forums. I haven't done much linux myself but I have been asked if I can do the following. Write a linux script that needs to scan a certain folder every x amount of minutes and if there is a file in the folder then it needs to call a different script. Is this... (2 Replies)
Discussion started by: Bosbaba
2 Replies

5. Shell Programming and Scripting

Script that delete a File when a DEL File will be placed in same folder

Hi there, i have a question. I have a folder called /usr/test There is a file in it.... test.csv I need not a shell script that checks if there is a file called: test.del And if the file is in the same folder then the script should delete the test.csv and also the test.del. Hope... (9 Replies)
Discussion started by: Bjoern28
9 Replies

6. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

7. Shell Programming and Scripting

shell script for moving all the file from the same folder

Hi , I need a shell script which basicaly moves all the files from one folder say folder x to folder y and once they are moved to folder y a datetimestamp should be attached to there name for ex file a should be moved to y folder and renamed as a_20081015 (1 Reply)
Discussion started by: viv1
1 Replies

8. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

9. Shell Programming and Scripting

Script to find a file in the other folder

Hi, I have two folders in two different directories.Both the folders contain set of text files. The name of the files are same in both the folders. I need to write a script to compare all the files in both the folders having same name. I am new to unix. Can you help me out in giving a script to... (4 Replies)
Discussion started by: ragavhere
4 Replies

10. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies
Login or Register to Ask a Question